mirror of
https://github.com/vishvananda/netlink.git
synced 2025-09-26 20:01:13 +08:00
geneve: Support setting/getting source port range
Add support for geneve feature to specify source port range, see kernel commits: - e1f95b1992b8 ("geneve: Allow users to specify source port range") - 5a41a00cd5d5 ("geneve, specs: Add port range to rt_link specification") This is exactly equivalent on what is done in case of vxlan today. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:

committed by
Alessandro Boch

parent
d85a66b0d8
commit
6b5dd30007
2
link.go
2
link.go
@@ -1059,6 +1059,8 @@ type Geneve struct {
|
||||
FlowBased bool
|
||||
InnerProtoInherit bool
|
||||
Df GeneveDf
|
||||
PortLow int
|
||||
PortHigh int
|
||||
}
|
||||
|
||||
func (geneve *Geneve) Attrs() *LinkAttrs {
|
||||
|
@@ -3100,6 +3100,10 @@ func linkFlags(rawFlags uint32) net.Flags {
|
||||
return f
|
||||
}
|
||||
|
||||
type genevePortRange struct {
|
||||
Lo, Hi uint16
|
||||
}
|
||||
|
||||
func addGeneveAttrs(geneve *Geneve, linkInfo *nl.RtAttr) {
|
||||
data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
|
||||
|
||||
@@ -3136,6 +3140,15 @@ func addGeneveAttrs(geneve *Geneve, linkInfo *nl.RtAttr) {
|
||||
data.AddRtAttr(nl.IFLA_GENEVE_TOS, nl.Uint8Attr(geneve.Tos))
|
||||
}
|
||||
|
||||
if geneve.PortLow > 0 || geneve.PortHigh > 0 {
|
||||
pr := genevePortRange{uint16(geneve.PortLow), uint16(geneve.PortHigh)}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
binary.Write(buf, binary.BigEndian, &pr)
|
||||
|
||||
data.AddRtAttr(nl.IFLA_GENEVE_PORT_RANGE, buf.Bytes())
|
||||
}
|
||||
|
||||
data.AddRtAttr(nl.IFLA_GENEVE_DF, nl.Uint8Attr(uint8(geneve.Df)))
|
||||
}
|
||||
|
||||
@@ -3157,6 +3170,13 @@ func parseGeneveData(link Link, data []syscall.NetlinkRouteAttr) {
|
||||
geneve.FlowBased = true
|
||||
case nl.IFLA_GENEVE_INNER_PROTO_INHERIT:
|
||||
geneve.InnerProtoInherit = true
|
||||
case nl.IFLA_GENEVE_PORT_RANGE:
|
||||
buf := bytes.NewBuffer(datum.Value[0:4])
|
||||
var pr genevePortRange
|
||||
if binary.Read(buf, binary.BigEndian, &pr) == nil {
|
||||
geneve.PortLow = int(pr.Lo)
|
||||
geneve.PortHigh = int(pr.Hi)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -438,6 +438,15 @@ func compareGeneve(t *testing.T, expected, actual *Geneve) {
|
||||
t.Fatal("Geneve.InnerProtoInherit doesn't match")
|
||||
}
|
||||
|
||||
if expected.PortLow > 0 || expected.PortHigh > 0 {
|
||||
if actual.PortLow != expected.PortLow {
|
||||
t.Fatal("Geneve.PortLow doesn't match")
|
||||
}
|
||||
if actual.PortHigh != expected.PortHigh {
|
||||
t.Fatal("Geneve.PortHigh doesn't match")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: we should implement the rest of the geneve methods
|
||||
}
|
||||
|
||||
|
@@ -234,6 +234,7 @@ const (
|
||||
IFLA_GENEVE_TTL_INHERIT
|
||||
IFLA_GENEVE_DF
|
||||
IFLA_GENEVE_INNER_PROTO_INHERIT
|
||||
IFLA_GENEVE_PORT_RANGE
|
||||
IFLA_GENEVE_MAX = IFLA_GENEVE_INNER_PROTO_INHERIT
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user