コード例 #1
0
ファイル: ethtool.py プロジェクト: vjuranek/vdsm
def driver_name(device_name):
    """Returns the driver used by a device.

    Throws IOError ENODEV for non existing devices.
    Throws IOError EOPNOTSUPP for non supported devices, i.g., loopback.
    """
    encoded_name = py2to3.to_binary(device_name)

    buff = array.array('b', b'\0' * struct.calcsize(DRVINFO_FORMAT))
    cmds = struct.pack('= I', ETHTOOL_GDRVINFO)
    buff[0:len(cmds)] = array.array('b', cmds)
    data = struct.pack(IFREQ_FORMAT, encoded_name, *buff.buffer_info())

    with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as sock:
        fcntl.ioctl(sock, SIOCETHTOOL, data)

    (
        cmds,
        driver,
        version,
        fw_version,
        businfo,
        _,
        _,
        n_priv_flags,
        n_stats,
        testinfo_len,
        eedump_len,
        regdump_len,
    ) = struct.unpack(DRVINFO_FORMAT, buff)
    driver_str = py2to3.to_str(driver)
    return driver_str.rstrip('\0')  # C string end with the leftmost null char
コード例 #2
0
def rtnl_link_get_kernel(socket, ifindex, ifname):
    """Get a link object directly from kernel.

    @arg socket          Netlink socket
    @arg ifindex         Interface index, use 0 if not to be used
    @arg ifname          Name of link, use None if not to be used

    Older kernels do not support lookup by name. In that case, libnl
    will fail with NLE_OPNOTSUPP. In case no matching link was found,
    fails with NLE_OBJ_NOTFOUND.

    @return Link object.
    """
    _rtnl_link_get_kernel = _libnl_route('rtnl_link_get_kernel', c_int,
                                         c_void_p, c_int, c_char_p, c_void_p)
    link = c_void_p()
    b_ifname = py2to3.to_binary(ifname) if ifname else None
    err = _rtnl_link_get_kernel(socket, ifindex, b_ifname, byref(link))
    if err:
        raise IOError(-err, nl_geterror(err))
    return link
コード例 #3
0
ファイル: libnl.py プロジェクト: nirs/vdsm
def rtnl_link_get_kernel(socket, ifindex, ifname):
    """Get a link object directly from kernel.

    @arg socket          Netlink socket
    @arg ifindex         Interface index, use 0 if not to be used
    @arg ifname          Name of link, use None if not to be used

    Older kernels do not support lookup by name. In that case, libnl
    will fail with NLE_OPNOTSUPP. In case no matching link was found,
    fails with NLE_OBJ_NOTFOUND.

    @return Link object.
    """
    _rtnl_link_get_kernel = _libnl_route(
        'rtnl_link_get_kernel', c_int, c_void_p, c_int, c_char_p, c_void_p)
    link = c_void_p()
    b_ifname = py2to3.to_binary(ifname) if ifname else None
    err = _rtnl_link_get_kernel(socket, ifindex, b_ifname, byref(link))
    if err:
        raise IOError(-err, nl_geterror(err))
    return link
コード例 #4
0
ファイル: ethtool.py プロジェクト: nirs/vdsm
def driver_name(device_name):
    """Returns the driver used by a device.

    Throws IOError ENODEV for non existing devices.
    Throws IOError EOPNOTSUPP for non supported devices, i.g., loopback.
    """
    encoded_name = py2to3.to_binary(device_name)

    buff = array.array('b', b'\0' * struct.calcsize(DRVINFO_FORMAT))
    cmds = struct.pack('= I', ETHTOOL_GDRVINFO)
    buff[0:len(cmds)] = array.array('b', cmds)
    data = struct.pack(IFREQ_FORMAT, encoded_name, *buff.buffer_info())

    with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as sock:
        fcntl.ioctl(sock, SIOCETHTOOL, data)

    (cmds, driver, version, fw_version, businfo, _, _, n_priv_flags, n_stats,
     testinfo_len, eedump_len, regdump_len) = struct.unpack(DRVINFO_FORMAT,
                                                            buff)
    driver_str = py2to3.to_str(driver)
    return driver_str.rstrip('\0')  # C string end with the leftmost null char