Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

if_link: Add additional parameter to IFLA_VF_INFO for spoof checking

Add configuration setting for drivers to turn spoof checking on or off
for discrete VFs.

v2 - Fix indentation problem, wrap the ifla_vf_info structure in
#ifdef __KERNEL__ to prevent user space from accessing and
change function paramater for the spoof check setting netdev
op from u8 to bool.
v3 - Preset spoof check setting to -1 so that user space tools such
as ip can detect that the driver didn't report a spoofcheck
setting. Prevents incorrect display of spoof check settings
for drivers that don't report it.

Signed-off-by: Greg Rose <gregory.v.rose@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>

authored by

Greg Rose and committed by
Jeff Kirsher
5f8444a3 a90b412c

+43 -3
+10
include/linux/if_link.h
··· 279 279 IFLA_VF_MAC, /* Hardware queue specific attributes */ 280 280 IFLA_VF_VLAN, 281 281 IFLA_VF_TX_RATE, /* TX Bandwidth Allocation */ 282 + IFLA_VF_SPOOFCHK, /* Spoof Checking on/off switch */ 282 283 __IFLA_VF_MAX, 283 284 }; 284 285 ··· 301 300 __u32 rate; /* Max TX bandwidth in Mbps, 0 disables throttling */ 302 301 }; 303 302 303 + struct ifla_vf_spoofchk { 304 + __u32 vf; 305 + __u32 setting; 306 + }; 307 + #ifdef __KERNEL__ 308 + 309 + /* We don't want this structure exposed to user space */ 304 310 struct ifla_vf_info { 305 311 __u32 vf; 306 312 __u8 mac[32]; 307 313 __u32 vlan; 308 314 __u32 qos; 309 315 __u32 tx_rate; 316 + __u32 spoofchk; 310 317 }; 318 + #endif 311 319 312 320 /* VF ports management section 313 321 *
+3
include/linux/netdevice.h
··· 781 781 * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac); 782 782 * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan, u8 qos); 783 783 * int (*ndo_set_vf_tx_rate)(struct net_device *dev, int vf, int rate); 784 + * int (*ndo_set_vf_spoofchk)(struct net_device *dev, int vf, bool setting); 784 785 * int (*ndo_get_vf_config)(struct net_device *dev, 785 786 * int vf, struct ifla_vf_info *ivf); 786 787 * int (*ndo_set_vf_port)(struct net_device *dev, int vf, ··· 901 900 int queue, u16 vlan, u8 qos); 902 901 int (*ndo_set_vf_tx_rate)(struct net_device *dev, 903 902 int vf, int rate); 903 + int (*ndo_set_vf_spoofchk)(struct net_device *dev, 904 + int vf, bool setting); 904 905 int (*ndo_get_vf_config)(struct net_device *dev, 905 906 int vf, 906 907 struct ifla_vf_info *ivf);
+30 -3
net/core/rtnetlink.c
··· 731 731 size += num_vfs * 732 732 (nla_total_size(sizeof(struct ifla_vf_mac)) + 733 733 nla_total_size(sizeof(struct ifla_vf_vlan)) + 734 - nla_total_size(sizeof(struct ifla_vf_tx_rate))); 734 + nla_total_size(sizeof(struct ifla_vf_tx_rate)) + 735 + nla_total_size(sizeof(struct ifla_vf_spoofchk))); 735 736 return size; 736 737 } else 737 738 return 0; ··· 955 954 struct ifla_vf_mac vf_mac; 956 955 struct ifla_vf_vlan vf_vlan; 957 956 struct ifla_vf_tx_rate vf_tx_rate; 957 + struct ifla_vf_spoofchk vf_spoofchk; 958 + 959 + /* 960 + * Not all SR-IOV capable drivers support the 961 + * spoofcheck query. Preset to -1 so the user 962 + * space tool can detect that the driver didn't 963 + * report anything. 964 + */ 965 + ivi.spoofchk = -1; 958 966 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi)) 959 967 break; 960 - vf_mac.vf = vf_vlan.vf = vf_tx_rate.vf = ivi.vf; 968 + vf_mac.vf = 969 + vf_vlan.vf = 970 + vf_tx_rate.vf = 971 + vf_spoofchk.vf = ivi.vf; 972 + 961 973 memcpy(vf_mac.mac, ivi.mac, sizeof(ivi.mac)); 962 974 vf_vlan.vlan = ivi.vlan; 963 975 vf_vlan.qos = ivi.qos; 964 976 vf_tx_rate.rate = ivi.tx_rate; 977 + vf_spoofchk.setting = ivi.spoofchk; 965 978 vf = nla_nest_start(skb, IFLA_VF_INFO); 966 979 if (!vf) { 967 980 nla_nest_cancel(skb, vfinfo); ··· 983 968 } 984 969 NLA_PUT(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac); 985 970 NLA_PUT(skb, IFLA_VF_VLAN, sizeof(vf_vlan), &vf_vlan); 986 - NLA_PUT(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate), &vf_tx_rate); 971 + NLA_PUT(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate), 972 + &vf_tx_rate); 973 + NLA_PUT(skb, IFLA_VF_SPOOFCHK, sizeof(vf_spoofchk), 974 + &vf_spoofchk); 987 975 nla_nest_end(skb, vf); 988 976 } 989 977 nla_nest_end(skb, vfinfo); ··· 1218 1200 if (ops->ndo_set_vf_tx_rate) 1219 1201 err = ops->ndo_set_vf_tx_rate(dev, ivt->vf, 1220 1202 ivt->rate); 1203 + break; 1204 + } 1205 + case IFLA_VF_SPOOFCHK: { 1206 + struct ifla_vf_spoofchk *ivs; 1207 + ivs = nla_data(vf); 1208 + err = -EOPNOTSUPP; 1209 + if (ops->ndo_set_vf_spoofchk) 1210 + err = ops->ndo_set_vf_spoofchk(dev, ivs->vf, 1211 + ivs->setting); 1221 1212 break; 1222 1213 } 1223 1214 default: