mirror of
https://github.com/vishvananda/netlink
synced 2024-12-28 17:52:28 +00:00
Add DestPort to TunnelKeyAction
Fix parsing of TCA_TUNNEL_KEY_ENC_IPV6_SRC & TCA_TUNNEL_KEY_ENC_IPV6_DST
This commit is contained in:
parent
339a215d65
commit
06362a6c16
@ -213,10 +213,11 @@ const (
|
||||
|
||||
type TunnelKeyAction struct {
|
||||
ActionAttrs
|
||||
Action TunnelKeyAct
|
||||
SrcAddr net.IP
|
||||
DstAddr net.IP
|
||||
KeyID uint32
|
||||
Action TunnelKeyAct
|
||||
SrcAddr net.IP
|
||||
DstAddr net.IP
|
||||
KeyID uint32
|
||||
DestPort uint16
|
||||
}
|
||||
|
||||
func (action *TunnelKeyAction) Type() string {
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"syscall"
|
||||
|
||||
"github.com/vishvananda/netlink/nl"
|
||||
@ -456,6 +455,9 @@ func EncodeActions(attr *nl.RtAttr, actions []Action) error {
|
||||
} else {
|
||||
return fmt.Errorf("invalid dst addr %s for tunnel_key action", action.DstAddr)
|
||||
}
|
||||
if action.DestPort != 0 {
|
||||
aopts.AddRtAttr(nl.TCA_TUNNEL_KEY_ENC_DST_PORT, htons(action.DestPort))
|
||||
}
|
||||
}
|
||||
case *SkbEditAction:
|
||||
table := attr.AddRtAttr(tabIndex, nil)
|
||||
@ -566,12 +568,12 @@ func parseActions(tables []syscall.NetlinkRouteAttr) ([]Action, error) {
|
||||
action.(*TunnelKeyAction).Action = TunnelKeyAct(tun.Action)
|
||||
case nl.TCA_TUNNEL_KEY_ENC_KEY_ID:
|
||||
action.(*TunnelKeyAction).KeyID = networkOrder.Uint32(adatum.Value[0:4])
|
||||
case nl.TCA_TUNNEL_KEY_ENC_IPV6_SRC:
|
||||
case nl.TCA_TUNNEL_KEY_ENC_IPV4_SRC:
|
||||
action.(*TunnelKeyAction).SrcAddr = net.IP(adatum.Value[:])
|
||||
case nl.TCA_TUNNEL_KEY_ENC_IPV6_DST:
|
||||
case nl.TCA_TUNNEL_KEY_ENC_IPV4_DST:
|
||||
action.(*TunnelKeyAction).DstAddr = net.IP(adatum.Value[:])
|
||||
case nl.TCA_TUNNEL_KEY_ENC_IPV6_SRC, nl.TCA_TUNNEL_KEY_ENC_IPV4_SRC:
|
||||
action.(*TunnelKeyAction).SrcAddr = adatum.Value[:]
|
||||
case nl.TCA_TUNNEL_KEY_ENC_IPV6_DST, nl.TCA_TUNNEL_KEY_ENC_IPV4_DST:
|
||||
action.(*TunnelKeyAction).DstAddr = adatum.Value[:]
|
||||
case nl.TCA_TUNNEL_KEY_ENC_DST_PORT:
|
||||
action.(*TunnelKeyAction).DestPort = ntohs(adatum.Value)
|
||||
}
|
||||
case "skbedit":
|
||||
switch adatum.Attr.Type {
|
||||
|
@ -1022,6 +1022,7 @@ func TestFilterU32TunnelKeyAddDel(t *testing.T) {
|
||||
tunnelAct.DstAddr = net.IPv4(10, 10, 10, 2)
|
||||
tunnelAct.KeyID = 0x01
|
||||
tunnelAct.Action = TCA_TUNNEL_KEY_SET
|
||||
tunnelAct.DestPort = 8472
|
||||
|
||||
classId := MakeHandle(1, 1)
|
||||
filter := &U32{
|
||||
@ -1088,6 +1089,9 @@ func TestFilterU32TunnelKeyAddDel(t *testing.T) {
|
||||
if tun.KeyID != tunnelAct.KeyID {
|
||||
t.Fatal("Action KeyID doesn't match")
|
||||
}
|
||||
if tun.DestPort != tunnelAct.DestPort {
|
||||
t.Fatal("Action DestPort doesn't match")
|
||||
}
|
||||
if tun.Action != tunnelAct.Action {
|
||||
t.Fatal("Action doesn't match")
|
||||
}
|
||||
|
@ -735,7 +735,13 @@ const (
|
||||
TCA_TUNNEL_KEY_ENC_IPV6_SRC
|
||||
TCA_TUNNEL_KEY_ENC_IPV6_DST
|
||||
TCA_TUNNEL_KEY_ENC_KEY_ID
|
||||
TCA_TUNNEL_KEY_MAX = TCA_TUNNEL_KEY_ENC_KEY_ID
|
||||
TCA_TUNNEL_KEY_PAD
|
||||
TCA_TUNNEL_KEY_ENC_DST_PORT
|
||||
TCA_TUNNEL_KEY_NO_CSUM
|
||||
TCA_TUNNEL_KEY_ENC_OPTS
|
||||
TCA_TUNNEL_KEY_ENC_TOS
|
||||
TCA_TUNNEL_KEY_ENC_TTL
|
||||
TCA_TUNNEL_KEY_MAX
|
||||
)
|
||||
|
||||
type TcTunnelKey struct {
|
||||
|
Loading…
Reference in New Issue
Block a user