Thread (45 messages) 45 messages, 5 authors, 2018-10-10

Re: [PATCH v2 10/10] kni: add API to set link status on kernel interface

From: Igor Ryzhov <hidden>
Date: 2018-08-30 10:33:00

Hi again,

Forgot to mention netif_carrier_off changes. Your changes are necessary for
correct link status management,
but netif_carrier_off call should also be added to kni_ioctl_create before
the register_netdev call.
That's needed for correct link status even before first call to ndo_open.

Best regards,
Igor

On Thu, Aug 30, 2018 at 12:49 PM, Igor Ryzhov [off-list ref] wrote:
Hi Dan,

We use KNI device exactly the same way you described – with IP addresses,
routing, etc.
And we also faced the same problem of having the actual link status in
Linux kernel.

There is a special callback for link state management in net_device_ops
for soft-devices like KNI called ndo_change_carrier.
Current KNI driver implements it already, you just need to write to
/sys/class/net/<iface>/carrier to change link status.

Right now we implement it on application side, but I think it'll be good
to have this in rte_kni API.

Here is our implementation:

static int
linux_set_carrier(const char *name, int status)
{
char path[64];
const char *carrier = status ? "1" : "0";
int fd, ret;

sprintf(path, "/sys/devices/virtual/net/%s/carrier", name);
fd = open(path, O_WRONLY);
if (fd == -1) {
return -errno;
}

ret = write(fd, carrier, 2);
if (ret == -1) {
close(fd);
return -errno;
}

close(fd);

return 0;
}

Best regards,
Igor

On Thu, Aug 30, 2018 at 2:10 AM, Stephen Hemminger <
stephen@networkplumber.org> wrote:
quoted
On Wed, 29 Aug 2018 19:41:23 -0300
Dan Gora [off-list ref] wrote:
quoted
On Wed, Aug 29, 2018 at 7:12 PM, Dan Gora [off-list ref] wrote:
quoted
On Wed, Aug 29, 2018 at 7:00 PM, Stephen Hemminger
[off-list ref] wrote:
quoted
quoted
quoted
quoted
Add a new API function to KNI, rte_kni_update_link() to allow
DPDK
quoted
quoted
quoted
quoted
quoted
quoted
applications to update the link state for the KNI network
interfaces
quoted
quoted
quoted
quoted
quoted
quoted
in the linux kernel.

Note that the default carrier state is set to off when the
interface
quoted
quoted
quoted
quoted
quoted
quoted
is opened.

Signed-off-by: Dan Gora <redacted>
Do you really need a special ioctl for this?
There is already ability to set link state via sysfs or netlink.
I think yes.. AFAIK sysfs does not constitute a stable API;
It is a stable API on Linux.
Actually this does not seem to be completely true...

From Documentation/admin-guide/sysfs-rules.rst:

Rules on how to access information in sysfs
===========================================

The kernel-exported sysfs exports internal kernel implementation details
and depends on internal kernel structures and layout. It is agreed upon
by the kernel developers that the Linux kernel does not provide a stable
internal API. Therefore, there are aspects of the sysfs interface that
may not be stable across kernel releases.

<snip>

- devices are only "devices"
    There is no such thing like class-, bus-, physical devices,
    interfaces, and such that you can rely on in userspace. Everything
is
quoted
    just simply a "device". Class-, bus-, physical, ... types are just
    kernel implementation details which should not be expected by
    applications that look for devices in sysfs.

    The properties of a device are:

    - devpath (``/devices/pci0000:00/0000:00:1d.1/usb2/2-2/2-2:1.0``)
<snip>

    - kernel name (``sda``, ``tty``, ``0000:00:1f.2``, ...)
<snip>

    - subsystem (``block``, ``tty``, ``pci``, ...)
<snip>

    - driver (``tg3``, ``ata_piix``, ``uhci_hcd``)
<snip>

    - attributes
<snip>

    Everything else is just a kernel driver-core implementation detail
    that should not be assumed to be stable across kernel releases.
Network device sysfs is stable. No one ever got around to putting it in
documentation
I wouldn't worry, once anything in /sys/class/net is added it is not
going to change without major breakage in many many tools.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help