Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify: don't send IFLA_INFO_KIND for Device types #1041

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aojea
Copy link
Contributor

@aojea aojea commented Dec 17, 2024

Device links are links created by udev and are not a supported Type, sending the "device" string as IFLA_INFO_KIND throws an -EOPNOTSUPP error.

Tested witht the followed code against a phisical interface

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/vishvananda/netlink"
	"github.com/vishvananda/netns"
)

func main() {

	if len(os.Args) != 3 {
		fmt.Printf("Usage: %s <interface> <namespace>\n", os.Args[0])
		os.Exit(1)
	}

	ifName := os.Args[1]
	ns := os.Args[2]

	link, err := netlink.LinkByName(ifName)
	if err != nil {
		log.Fatal("linkbyname failed", err)
	}

	err = netlink.LinkSetDown(link)
	if err != nil {
		log.Fatal("LinkSetDown failed", err)
	}

	attrs := netlink.NewLinkAttrs()
	attrs.Index = link.Attrs().Index
	attrs.MTU = link.Attrs().MTU
	attrs.Name = link.Attrs().Name

	containerNs, err := netns.GetFromPath(ns)
	if err != nil {
		log.Fatal("container from path", err)
	}
	attrs.Namespace = netlink.NsFd(containerNs)
	dev := &netlink.Device{
		LinkAttrs: attrs,
	}
	err = netlink.LinkModify(dev)
	if err != nil {
		log.Fatal("link modify", err)
	}
}

Without the patch:

link-setns eth3 /var/run/netns/cni-e79e4127-2e60-56fd-4ade-14b420c65de3
2024/12/17 12:53:38 operation not supported

With this patch:

$ link-setns eth4 /var/run/netns/cni-e79e4127-2e60-56fd-4ade-14b420c65de3
$ echo $?
0
$  ip netns exec cni-e79e4127-2e60-56fd-4ade-14b420c65de3  ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc noqueue state UP group default
    link/ether f6:47:24:b8:93:44 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.52.3.110/24 brd 10.52.3.255 scope global eth0
       valid_lft forever preferred_lft forever
6: eth4: <BROADCAST,MULTICAST> mtu 8244 qdisc noop state DOWN group default qlen 1000
    link/ether 42:01:c0:a8:04:02 brd ff:ff:ff:ff:ff:ff

Device links are links created by udev and are not a supported Type,
sending the "device" string as IFLA_INFO_KIND throws an -EOPNOTSUPP error.

Change-Id: I5c1aa7a530f0ea3f7450b61242149b8c45dd67c9
Signed-off-by: Antonio Ojea <aojea@google.com>
@aojea
Copy link
Contributor Author

aojea commented Dec 17, 2024

failed test is

    --- FAIL: TestRuleListFiltered/IPv4/returns_rules_filtered_by_fwmark_0xFFFFFFFF/0 (0.00s)

does not seem related, does it?

@aojea aojea closed this Dec 17, 2024
@aojea aojea reopened this Dec 17, 2024
@aojea
Copy link
Contributor Author

aojea commented Dec 17, 2024

hmm, now it failed

    --- FAIL: TestRuleListFiltered/IPv6/returns_rules_with_specific_priority (0.00s)

two time in a row but this patch is not exercising this code

@aojea aojea closed this Dec 17, 2024
@aojea aojea reopened this Dec 17, 2024
@aojea
Copy link
Contributor Author

aojea commented Dec 17, 2024

it failed again

    --- FAIL: TestRuleListFiltered/IPv4/returns_rules_filtered_by_fwmark_0x1234 (0.00s)

let me try locally now I'm worried I'm doing something wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant