Skip to content

Commit df4edaa

Browse files
jrifealbertjin
authored andcommitted
Add support for the expires option of ip route
1. fix rule test failed when rule add slow. disable broadcast if broadcast is set to net.IPv4zero remove comments about broadcast when deleting address remove another comment about broadcast auto calculation .github/workflows: Bump CI Go version to v1.22 Update the Go version we test against to Go v1.22 which is currently the oldest version still receiving security updates. Signed-off-by: Dylan Reimerink <[email protected]> 1. filter match support vlanId and srcMac, dstMac. 2. filter action support vlan pop/push. link_linux: Add deserialization of `IFF_RUNNING` flag Add deserialization of the `IFF_RUNNING` link flag which translates to `net.FlagRunning`. Signed-off-by: Dylan Reimerink <[email protected]> Preserve results when NLM_F_DUMP_INTR is set Similar to #1018, but for ConntrackDeleteFilters() Relates to kubernetes/kubernetes#129562 Add IFLA_PARENT_DEV_NAME / IFLA_PARENT_DEV_BUS_NAME to links These attributes are supported since kernel v5.14 (see [1]). Here's what iproute2 shows: ``` $ ip -d link show eth0 4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 65535 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 ... parentbus virtio parentdev virtio0 ``` [1]: torvalds/linux@00e77ed Signed-off-by: Albin Kerouanton <[email protected]> conntrack: prevent potential memory leak Currently, the ConntrackDeleteFilters captures all flow entries it fails to delete and reports them as errors. This behavior can potentially lead to memory leaks in high-traffic systems, where thousands of conntrack flow entries are cleared in a single batch. With this commit, instead of returning all the un-deleted flow entries, we now return a single error message for all of them. Signed-off-by: Daman Arora <[email protected]> Fix parsing 4-bytes attribute What if the data length of attribute is 4? The attribute will be ignored, because `i+4 < len(data)`. Signed-off-by: Leon Hwang <[email protected]> fix: Use correct offset for unix socket diagnosis Signed-off-by: Sven Rebhan <[email protected]> vxlan: Fix parseVxlanData for source port range binary.Read() != nil check means error case, so the vxlan.Port{Low,High} are never populated. Fix the check. Signed-off-by: Daniel Borkmann <[email protected]> netkit: Allow setting MAC address in L2 mode Signed-off-by: Jordan Rife <[email protected]> Add support for MTU Lock When adding a route with "mtu lock <mtu>" path MTU discovery (PMTUD) will not be tried and packets will be sent without DF bit set. Upon receiving an ICMP needs frag due to PMTUD, the kernel will not install a cached route and lower the MTU. Signed-off-by: Tim Rozet <[email protected]> pedit: Fix EncodeActions to add TcGen for pedit action TcGen was missing in pedit action and the kernel cannont correctly process pedit action. Signed-off-by: Chen Tang <[email protected]> go.mod: github.com/vishvananda/netns v0.0.5 - Adding file path for nerdctl and finch full diff: vishvananda/netns@v0.0.4...v0.0.5 Signed-off-by: Sebastiaan van Stijn <[email protected]> Add `OifIndex` option for `RouteGetWithOptions` The `RouteGetWithOptions` function currently has a `Oif` option which gets translated from link name to link index via a `LinkByName` call. This adds unnecessary overhead when the link index is already known. This commit adds a new `OifIndex` option to `RouteGetWithOptions` which can be specified instead of `Oif` to skip the internal link index translation. Signed-off-by: Dylan Reimerink <[email protected]> Support "sample" filter action This change adds support for packet sampling using "psample" kernel module. Added PCPU and SA fields to XfrmState Add support for ARP/ND Timestamps when retriving neighbors On Linux, Netlink provides NDA_CACHEINFO which carries timestamps about when ARP/ND was updated, used, and confirmed. Expose these fields in the Neigh type tuntap: parse additional netlink attributes for flags and queues Signed-off-by: Ivan Tsvetkov <[email protected]> tuntap: add support for dynamically managing multi-queue FDs Introduce AddQueues and RemoveQueues methods for attaching and detaching queue file descriptors to an existing TUN/TAP interface in multi-queue mode. This enables controlled testing of disabled queues and fine-grained queue management without relying on interface recreation. Signed-off-by: Ivan Tsvetkov <[email protected]> add SRv6 support for END.DT4 fix: add missing CLOEXEC flag Some calls were already using it, some were not, but fix the remaining ones. Without this flag, the file descriptor would to the child process after fork/exec. Signed-off-by: Andrey Smirnov <[email protected]> tests: Improve address unit test infrastructure Signed-off-by: [email protected] <[email protected]> addr_linux: don't require label to be prefixed with interface name This requirement limits the usefulness of labels (given the total label length can only be 15 characters). Signed-off-by: Julian Wiedmann <[email protected]> feat: add IFLA_INET6_ADDR_GEN_MODE support 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 <[email protected]> feat: add support for RtoMin lock veth: allow configuring peer attributes beyond namespace and address Signed-off-by: Gwendolyn <[email protected]> qdisc: fix wrong type info of tc_sfq_qopt Mimic `ipset` C code for determining correct default ipset revision Signed-off-by: Benjamin Leggett <[email protected]> bugfix: parse ipv4 src/dst error rdma: support rdma metrics: resource and statistic Signed-off-by: bingshen.wbs <[email protected]> feat: add vlanid - tunnelid mapping support filter: add classid and port range support for flower vlan: add support for flags and qos maps Signed-off-by: Gwendolyn <[email protected]> Add support for the `expires` option of `ip route`
1 parent 17daef6 commit df4edaa

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

route.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,18 @@ type Encap interface {
4545
Equal(Encap) bool
4646
}
4747

48-
// Protocol describe what was the originator of the route
48+
type RouteCacheInfo struct {
49+
Users uint32
50+
Age uint32
51+
Expires int32
52+
Error uint32
53+
Used uint32
54+
Id uint32
55+
Ts uint32
56+
Tsage uint32
57+
}
58+
59+
//Protocol describe what was the originator of the route
4960
type RouteProtocol int
5061

5162
// Route represents a netlink route.
@@ -87,6 +98,8 @@ type Route struct {
8798
QuickACK int
8899
Congctl string
89100
FastOpenNoCookie int
101+
Expires int
102+
CacheInfo *RouteCacheInfo
90103
}
91104

92105
func (r Route) String() string {
@@ -117,6 +130,9 @@ func (r Route) String() string {
117130
elems = append(elems, fmt.Sprintf("Flags: %s", r.ListFlags()))
118131
elems = append(elems, fmt.Sprintf("Table: %d", r.Table))
119132
elems = append(elems, fmt.Sprintf("Realm: %d", r.Realm))
133+
if r.Expires != 0 {
134+
elems = append(elems, fmt.Sprintf("Expires: %dsec", r.Expires))
135+
}
120136
return fmt.Sprintf("{%s}", strings.Join(elems, " "))
121137
}
122138

route_linux.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,12 @@ func (h *Handle) prepareRouteReq(route *Route, req *nl.NetlinkRequest, msg *nl.R
10861086
msg.Type = uint8(route.Type)
10871087
}
10881088

1089+
if route.Expires > 0 {
1090+
b := make([]byte, 4)
1091+
native.PutUint32(b, uint32(route.Expires))
1092+
rtAttrs = append(rtAttrs, nl.NewRtAttr(unix.RTA_EXPIRES, b))
1093+
}
1094+
10891095
var metrics []*nl.RtAttr
10901096
if route.MTU > 0 {
10911097
b := nl.Uint32Attr(uint32(route.MTU))
@@ -1320,6 +1326,25 @@ func (h *Handle) RouteListFilteredIter(family int, filter *Route, filterMask uin
13201326
return executeErr
13211327
}
13221328

1329+
// deserializeRouteCacheInfo decodes a RTA_CACHEINFO attribute into a RouteCacheInfo struct
1330+
func deserializeRouteCacheInfo(b []byte) (*RouteCacheInfo, error) {
1331+
if len(b) != 32 {
1332+
return nil, unix.EINVAL
1333+
}
1334+
1335+
e := nl.NativeEndian()
1336+
return &RouteCacheInfo{
1337+
e.Uint32(b),
1338+
e.Uint32(b[4:]),
1339+
int32(e.Uint32(b[8:])),
1340+
e.Uint32(b[12:]),
1341+
e.Uint32(b[16:]),
1342+
e.Uint32(b[20:]),
1343+
e.Uint32(b[24:]),
1344+
e.Uint32(b[28:]),
1345+
}, nil
1346+
}
1347+
13231348
// deserializeRoute decodes a binary netlink message into a Route struct
13241349
func deserializeRoute(m []byte) (Route, error) {
13251350
msg := nl.DeserializeRtMsg(m)
@@ -1363,6 +1388,12 @@ func deserializeRoute(m []byte) (Route, error) {
13631388
route.ILinkIndex = int(native.Uint32(attr.Value[0:4]))
13641389
case unix.RTA_PRIORITY:
13651390
route.Priority = int(native.Uint32(attr.Value[0:4]))
1391+
case unix.RTA_CACHEINFO:
1392+
route.CacheInfo, err = deserializeRouteCacheInfo(attr.Value)
1393+
if err != nil {
1394+
return route, err
1395+
}
1396+
route.Expires = int(route.CacheInfo.Expires) / 100
13661397
case unix.RTA_FLOW:
13671398
route.Realm = int(native.Uint32(attr.Value[0:4]))
13681399
case unix.RTA_TABLE:

route_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func TestRoute6AddDel(t *testing.T) {
192192
IP: net.ParseIP("2001:db8::0"),
193193
Mask: net.CIDRMask(64, 128),
194194
}
195-
route := Route{LinkIndex: link.Attrs().Index, Dst: dst}
195+
route := Route{LinkIndex: link.Attrs().Index, Dst: dst, Expires: 10}
196196
if err := RouteAdd(&route); err != nil {
197197
t.Fatal(err)
198198
}
@@ -204,6 +204,25 @@ func TestRoute6AddDel(t *testing.T) {
204204
t.Fatal("Route not added properly")
205205
}
206206

207+
// route expiry is supported by kernel 4.4+
208+
k, m, err := KernelVersion()
209+
if err != nil {
210+
t.Fatal(err)
211+
}
212+
if k > 4 || (k == 4 && m > 4) {
213+
foundExpires := false
214+
for _, route := range routes {
215+
if route.Dst.IP.Equal(dst.IP) {
216+
if route.Expires > 0 && route.Expires <= 10 {
217+
foundExpires = true
218+
}
219+
}
220+
}
221+
if !foundExpires {
222+
t.Fatal("Route 'expires' not set")
223+
}
224+
}
225+
207226
dstIP := net.ParseIP("2001:db8::1")
208227
routeToDstIP, err := RouteGet(dstIP)
209228
if err != nil {

0 commit comments

Comments
 (0)