1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

Merge pull request #12874 from yuwata/ethtool-make-ubsan-quiet

ethtool: make UBSan quiet and add missing link modes
This commit is contained in:
Lennart Poettering 2019-06-25 09:28:21 +02:00 committed by GitHub
commit 2d901d33a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 137 additions and 69 deletions

View File

@ -57,58 +57,73 @@ static const char* const netdev_feature_table[_NET_DEV_FEAT_MAX] = {
};
static const char* const ethtool_link_mode_bit_table[] = {
[ETHTOOL_LINK_MODE_10baseT_Half_BIT] = "10baset-half",
[ETHTOOL_LINK_MODE_10baseT_Full_BIT] = "10baset-full",
[ETHTOOL_LINK_MODE_100baseT_Half_BIT] = "100baset-half",
[ETHTOOL_LINK_MODE_100baseT_Full_BIT] = "100baset-full",
[ETHTOOL_LINK_MODE_1000baseT_Half_BIT] = "1000baset-half",
[ETHTOOL_LINK_MODE_1000baseT_Full_BIT] = "1000baset-full",
[ETHTOOL_LINK_MODE_Autoneg_BIT] = "autonegotiation",
[ETHTOOL_LINK_MODE_TP_BIT] = "tp",
[ETHTOOL_LINK_MODE_AUI_BIT] = "aui",
[ETHTOOL_LINK_MODE_MII_BIT] = "mii",
[ETHTOOL_LINK_MODE_FIBRE_BIT] = "fibre",
[ETHTOOL_LINK_MODE_BNC_BIT] = "bnc",
[ETHTOOL_LINK_MODE_10000baseT_Full_BIT] = "10000baset-full",
[ETHTOOL_LINK_MODE_Pause_BIT] = "pause",
[ETHTOOL_LINK_MODE_Asym_Pause_BIT] = "asym-pause",
[ETHTOOL_LINK_MODE_2500baseX_Full_BIT] = "2500basex-full",
[ETHTOOL_LINK_MODE_Backplane_BIT] = "backplane",
[ETHTOOL_LINK_MODE_1000baseKX_Full_BIT] = "1000basekx-full",
[ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT] = "10000basekx4-full",
[ETHTOOL_LINK_MODE_10000baseKR_Full_BIT] = "10000basekr-full",
[ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] = "10000baser-fec",
[ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT] = "20000basemld2-full",
[ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT] = "20000basekr2-full",
[ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT] = "40000basekr4-full",
[ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT] = "40000basecr4-full",
[ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT] = "40000basesr4-full",
[ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT] = "40000baselr4-full",
[ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT] = "56000basekr4-full",
[ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT] = "56000basecr4-full",
[ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT] = "56000basesr4-full",
[ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT] = "56000baselr4-full",
[ETHTOOL_LINK_MODE_25000baseCR_Full_BIT] = "25000basecr-full",
[ETHTOOL_LINK_MODE_25000baseKR_Full_BIT] = "25000basekr-full",
[ETHTOOL_LINK_MODE_25000baseSR_Full_BIT] = "25000basesr-full",
[ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT] = "50000basecr2-full",
[ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT] = "50000basekr2-full",
[ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT] = "100000basekr4-full",
[ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT] = "100000basesr4-full",
[ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT] = "100000basecr4-full",
[ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT] = "100000baselr4-er4-full",
[ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT] = "50000basesr2-full",
[ETHTOOL_LINK_MODE_1000baseX_Full_BIT] = "1000basex-full",
[ETHTOOL_LINK_MODE_10000baseCR_Full_BIT] = "10000basecr-full",
[ETHTOOL_LINK_MODE_10000baseSR_Full_BIT] = "10000basesr-full",
[ETHTOOL_LINK_MODE_10000baseLR_Full_BIT] = "10000baselr-full",
[ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT] = "10000baselrm-full",
[ETHTOOL_LINK_MODE_10000baseER_Full_BIT] = "10000baseer-full",
[ETHTOOL_LINK_MODE_2500baseT_Full_BIT] = "2500baset-full",
[ETHTOOL_LINK_MODE_5000baseT_Full_BIT] = "5000baset-full",
[ETHTOOL_LINK_MODE_FEC_NONE_BIT] = "fec-none",
[ETHTOOL_LINK_MODE_FEC_RS_BIT] = "fec-rs",
[ETHTOOL_LINK_MODE_FEC_BASER_BIT] = "fec-baser",
[ETHTOOL_LINK_MODE_10baseT_Half_BIT] = "10baset-half",
[ETHTOOL_LINK_MODE_10baseT_Full_BIT] = "10baset-full",
[ETHTOOL_LINK_MODE_100baseT_Half_BIT] = "100baset-half",
[ETHTOOL_LINK_MODE_100baseT_Full_BIT] = "100baset-full",
[ETHTOOL_LINK_MODE_1000baseT_Half_BIT] = "1000baset-half",
[ETHTOOL_LINK_MODE_1000baseT_Full_BIT] = "1000baset-full",
[ETHTOOL_LINK_MODE_Autoneg_BIT] = "autonegotiation",
[ETHTOOL_LINK_MODE_TP_BIT] = "tp",
[ETHTOOL_LINK_MODE_AUI_BIT] = "aui",
[ETHTOOL_LINK_MODE_MII_BIT] = "mii",
[ETHTOOL_LINK_MODE_FIBRE_BIT] = "fibre",
[ETHTOOL_LINK_MODE_BNC_BIT] = "bnc",
[ETHTOOL_LINK_MODE_10000baseT_Full_BIT] = "10000baset-full",
[ETHTOOL_LINK_MODE_Pause_BIT] = "pause",
[ETHTOOL_LINK_MODE_Asym_Pause_BIT] = "asym-pause",
[ETHTOOL_LINK_MODE_2500baseX_Full_BIT] = "2500basex-full",
[ETHTOOL_LINK_MODE_Backplane_BIT] = "backplane",
[ETHTOOL_LINK_MODE_1000baseKX_Full_BIT] = "1000basekx-full",
[ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT] = "10000basekx4-full",
[ETHTOOL_LINK_MODE_10000baseKR_Full_BIT] = "10000basekr-full",
[ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] = "10000baser-fec",
[ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT] = "20000basemld2-full",
[ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT] = "20000basekr2-full",
[ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT] = "40000basekr4-full",
[ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT] = "40000basecr4-full",
[ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT] = "40000basesr4-full",
[ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT] = "40000baselr4-full",
[ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT] = "56000basekr4-full",
[ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT] = "56000basecr4-full",
[ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT] = "56000basesr4-full",
[ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT] = "56000baselr4-full",
[ETHTOOL_LINK_MODE_25000baseCR_Full_BIT] = "25000basecr-full",
[ETHTOOL_LINK_MODE_25000baseKR_Full_BIT] = "25000basekr-full",
[ETHTOOL_LINK_MODE_25000baseSR_Full_BIT] = "25000basesr-full",
[ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT] = "50000basecr2-full",
[ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT] = "50000basekr2-full",
[ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT] = "100000basekr4-full",
[ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT] = "100000basesr4-full",
[ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT] = "100000basecr4-full",
[ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT] = "100000baselr4-er4-full",
[ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT] = "50000basesr2-full",
[ETHTOOL_LINK_MODE_1000baseX_Full_BIT] = "1000basex-full",
[ETHTOOL_LINK_MODE_10000baseCR_Full_BIT] = "10000basecr-full",
[ETHTOOL_LINK_MODE_10000baseSR_Full_BIT] = "10000basesr-full",
[ETHTOOL_LINK_MODE_10000baseLR_Full_BIT] = "10000baselr-full",
[ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT] = "10000baselrm-full",
[ETHTOOL_LINK_MODE_10000baseER_Full_BIT] = "10000baseer-full",
[ETHTOOL_LINK_MODE_2500baseT_Full_BIT] = "2500baset-full",
[ETHTOOL_LINK_MODE_5000baseT_Full_BIT] = "5000baset-full",
[ETHTOOL_LINK_MODE_FEC_NONE_BIT] = "fec-none",
[ETHTOOL_LINK_MODE_FEC_RS_BIT] = "fec-rs",
[ETHTOOL_LINK_MODE_FEC_BASER_BIT] = "fec-baser",
[ETHTOOL_LINK_MODE_50000baseKR_Full_BIT] = "50000basekr_full",
[ETHTOOL_LINK_MODE_50000baseSR_Full_BIT] = "50000basesr_full",
[ETHTOOL_LINK_MODE_50000baseCR_Full_BIT] = "50000basecr_full",
[ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT] = "50000baselr_er_fr_full",
[ETHTOOL_LINK_MODE_50000baseDR_Full_BIT] = "50000basedr_full",
[ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT] = "100000basekr2_full",
[ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT] = "100000basesr2_full",
[ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT] = "100000basecr2_full",
[ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT] = "100000baselr2_er2_fr2_full",
[ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT] = "100000basedr2_full",
[ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT] = "200000basekr4_full",
[ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT] = "200000basesr4_full",
[ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT] = "200000basecr4_full",
[ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT] = "200000baselr4_er4_fr4_full",
[ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT] = "200000basedr4_full",
};
/* Make sure the array is large enough to fit all bits */
assert_cc((ELEMENTSOF(ethtool_link_mode_bit_table)-1) / 32 < N_ADVERTISE);
@ -186,8 +201,13 @@ int ethtool_get_link_info(int *fd, const char *ifname,
if (ret_autonegotiation)
*ret_autonegotiation = ecmd.autoneg;
if (ret_speed)
*ret_speed = ethtool_cmd_speed(&ecmd) * 1000 * 1000;
if (ret_speed) {
uint32_t speed;
speed = ethtool_cmd_speed(&ecmd);
*ret_speed = speed == (uint32_t) SPEED_UNKNOWN ?
SIZE_MAX : (size_t) speed * 1000 * 1000;
}
if (ret_duplex)
*ret_duplex = ecmd.duplex;

View File

@ -6,7 +6,7 @@
#include "conf-parser.h"
#define N_ADVERTISE 2
#define N_ADVERTISE 3
/* we can't use DUPLEX_ prefix, as it
* clashes with <linux/ethtool.h> */

View File

@ -1,8 +1,8 @@
The files in this directory are copied from kernel-5.0, and the following modifications are applied:
The files in this directory are copied from kernel-5.2, and the following modifications are applied:
- auto_dev-ioctl.h: set AUTOFS_DEV_IOCTL_VERSION_MINOR to 0
- auto_dev-ioctl.h: define AUTOFS_IOCTL if not defined
- bpf_insn.h: This is imported from samples/bpf/bpf_insn.h
- bpf_insn.h: BPF_JMP_A() macro is also imported from include/linux/filter.h
- dm-ioctl.h: set DM_VERSION_MINOR to 27
- ethtool.h: add a type cast to SPEED_UNKNOWN
- ethtool.h: define __KERNEL_DIV_ROUND_UP if not defined
- ethtool.h: add casts in ethtool_cmd_speed()

View File

@ -164,6 +164,16 @@ struct bpf_insn;
.off = OFF, \
.imm = 0 })
/* Like BPF_JMP_REG, but with 32-bit wide operands for comparison. */
#define BPF_JMP32_REG(OP, DST, SRC, OFF) \
((struct bpf_insn) { \
.code = BPF_JMP32 | BPF_OP(OP) | BPF_X, \
.dst_reg = DST, \
.src_reg = SRC, \
.off = OFF, \
.imm = 0 })
/* Conditional jumps against immediates, if (dst_reg 'op' imm32) goto pc + off16 */
#define BPF_JMP_IMM(OP, DST, IMM, OFF) \
@ -174,6 +184,16 @@ struct bpf_insn;
.off = OFF, \
.imm = IMM })
/* Like BPF_JMP_IMM, but with 32-bit wide operands for comparison. */
#define BPF_JMP32_IMM(OP, DST, IMM, OFF) \
((struct bpf_insn) { \
.code = BPF_JMP32 | BPF_OP(OP) | BPF_K, \
.dst_reg = DST, \
.src_reg = 0, \
.off = OFF, \
.imm = IMM })
#define BPF_JMP_A(OFF) \
((struct bpf_insn) { \
.code = BPF_JMP | BPF_JA, \

View File

@ -272,7 +272,7 @@ enum {
#define DM_VERSION_MAJOR 4
#define DM_VERSION_MINOR 27
#define DM_VERSION_PATCHLEVEL 0
#define DM_VERSION_EXTRA "-ioctl (2018-04-03)"
#define DM_VERSION_EXTRA "-ioctl (2019-01-18)"
/* Status bits */
#define DM_READONLY_FLAG (1 << 0) /* In/Out */

View File

@ -126,7 +126,7 @@ static inline void ethtool_cmd_speed_set(struct ethtool_cmd *ep,
static inline __u32 ethtool_cmd_speed(const struct ethtool_cmd *ep)
{
return (ep->speed_hi << 16) | ep->speed;
return ((__u32) ep->speed_hi << 16) | (__u32) ep->speed;
}
/* Device supports clause 22 register access to PHY or peripherals
@ -256,9 +256,17 @@ struct ethtool_tunable {
#define DOWNSHIFT_DEV_DEFAULT_COUNT 0xff
#define DOWNSHIFT_DEV_DISABLE 0
/* Time in msecs after which link is reported as down
* 0 = lowest time supported by the PHY
* 0xff = off, link down detection according to standard
*/
#define ETHTOOL_PHY_FAST_LINK_DOWN_ON 0
#define ETHTOOL_PHY_FAST_LINK_DOWN_OFF 0xff
enum phy_tunable_id {
ETHTOOL_PHY_ID_UNSPEC,
ETHTOOL_PHY_DOWNSHIFT,
ETHTOOL_PHY_FAST_LINK_DOWN,
/*
* Add your fresh new phy tunable attribute above and remember to update
* phy_tunable_strings[] in net/core/ethtool.c
@ -1436,6 +1444,13 @@ enum ethtool_link_mode_bit_indices {
ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT = 29,
ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT = 30,
ETHTOOL_LINK_MODE_25000baseCR_Full_BIT = 31,
/* Last allowed bit for __ETHTOOL_LINK_MODE_LEGACY_MASK is bit
* 31. Please do NOT define any SUPPORTED_* or ADVERTISED_*
* macro for bits > 31. The only way to use indices > 31 is to
* use the new ETHTOOL_GLINKSETTINGS/ETHTOOL_SLINKSETTINGS API.
*/
ETHTOOL_LINK_MODE_25000baseKR_Full_BIT = 32,
ETHTOOL_LINK_MODE_25000baseSR_Full_BIT = 33,
ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT = 34,
@ -1457,15 +1472,24 @@ enum ethtool_link_mode_bit_indices {
ETHTOOL_LINK_MODE_FEC_NONE_BIT = 49,
ETHTOOL_LINK_MODE_FEC_RS_BIT = 50,
ETHTOOL_LINK_MODE_FEC_BASER_BIT = 51,
ETHTOOL_LINK_MODE_50000baseKR_Full_BIT = 52,
ETHTOOL_LINK_MODE_50000baseSR_Full_BIT = 53,
ETHTOOL_LINK_MODE_50000baseCR_Full_BIT = 54,
ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT = 55,
ETHTOOL_LINK_MODE_50000baseDR_Full_BIT = 56,
ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT = 57,
ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT = 58,
ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT = 59,
ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT = 60,
ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT = 61,
ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT = 62,
ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT = 63,
ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT = 64,
ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT = 65,
ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT = 66,
/* Last allowed bit for __ETHTOOL_LINK_MODE_LEGACY_MASK is bit
* 31. Please do NOT define any SUPPORTED_* or ADVERTISED_*
* macro for bits > 31. The only way to use indices > 31 is to
* use the new ETHTOOL_GLINKSETTINGS/ETHTOOL_SLINKSETTINGS API.
*/
__ETHTOOL_LINK_MODE_LAST
= ETHTOOL_LINK_MODE_FEC_BASER_BIT,
/* must be last entry */
__ETHTOOL_LINK_MODE_MASK_NBITS
};
#define __ETHTOOL_LINK_MODE_LEGACY_MASK(base_name) \
@ -1573,12 +1597,13 @@ enum ethtool_link_mode_bit_indices {
#define SPEED_50000 50000
#define SPEED_56000 56000
#define SPEED_100000 100000
#define SPEED_200000 200000
#define SPEED_UNKNOWN ((__u32) -1)
#define SPEED_UNKNOWN -1
static inline int ethtool_validate_speed(__u32 speed)
{
return speed <= INT_MAX || speed == SPEED_UNKNOWN;
return speed <= INT_MAX || speed == (__u32)SPEED_UNKNOWN;
}
/* Duplex, half or full. */
@ -1691,6 +1716,9 @@ static inline int ethtool_validate_duplex(__u8 duplex)
#define ETH_MODULE_SFF_8436 0x4
#define ETH_MODULE_SFF_8436_LEN 256
#define ETH_MODULE_SFF_8636_MAX_LEN 640
#define ETH_MODULE_SFF_8436_MAX_LEN 640
/* Reset flags */
/* The reset() operation must clear the flags for the components which
* were actually reset. On successful return, the flags indicate the