mirror of
https://github.com/vishvananda/netlink
synced 2025-04-01 22:58:37 +00:00
Add support for setting trust state of a VF
Add support for setting trust state of a VF. This allows restricting certain operations on VF when its untrusted such as disabling promiscuous mode. Signed-off-by: Parav Pandit <parav@mellanox.com>
This commit is contained in:
parent
a956595377
commit
70cf3c74a8
@ -413,6 +413,40 @@ func (h *Handle) LinkSetVfSpoofchk(link Link, vf int, check bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// LinkSetVfTrust enables/disables trust state on a vf for the link.
|
||||
// Equivalent to: `ip link set $link vf $vf trust $state`
|
||||
func LinkSetTrust(link Link, vf int, state bool) error {
|
||||
return pkgHandle.LinkSetVfTrust(link, vf, state)
|
||||
}
|
||||
|
||||
// LinkSetVfTrust enables/disables trust state on a vf for the link.
|
||||
// Equivalent to: `ip link set $link vf $vf trust $state`
|
||||
func (h *Handle) LinkSetVfTrust(link Link, vf int, state bool) error {
|
||||
var setting uint32
|
||||
base := link.Attrs()
|
||||
h.ensureIndex(base)
|
||||
req := h.newNetlinkRequest(syscall.RTM_SETLINK, syscall.NLM_F_ACK)
|
||||
|
||||
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
|
||||
msg.Index = int32(base.Index)
|
||||
req.AddData(msg)
|
||||
|
||||
data := nl.NewRtAttr(nl.IFLA_VFINFO_LIST, nil)
|
||||
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil)
|
||||
if state {
|
||||
setting = 1
|
||||
}
|
||||
vfmsg := nl.VfTrust{
|
||||
Vf: uint32(vf),
|
||||
Setting: setting,
|
||||
}
|
||||
nl.NewRtAttrChild(info, nl.IFLA_VF_TRUST, vfmsg.Serialize())
|
||||
req.AddData(data)
|
||||
|
||||
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
|
||||
return err
|
||||
}
|
||||
|
||||
// LinkSetMaster sets the master of the link device.
|
||||
// Equivalent to: `ip link set $link master $master`
|
||||
func LinkSetMaster(link Link, master *Bridge) error {
|
||||
|
@ -231,7 +231,8 @@ const (
|
||||
* on/off switch
|
||||
*/
|
||||
IFLA_VF_STATS /* network device statistics */
|
||||
IFLA_VF_MAX = IFLA_VF_STATS
|
||||
IFLA_VF_TRUST /* Trust state of VF */
|
||||
IFLA_VF_MAX = IFLA_VF_TRUST
|
||||
)
|
||||
|
||||
const (
|
||||
@ -259,6 +260,7 @@ const (
|
||||
SizeofVfSpoofchk = 0x08
|
||||
SizeofVfLinkState = 0x08
|
||||
SizeofVfRssQueryEn = 0x08
|
||||
SizeofVfTrust = 0x08
|
||||
)
|
||||
|
||||
// struct ifla_vf_mac {
|
||||
@ -419,6 +421,28 @@ func (msg *VfRssQueryEn) Serialize() []byte {
|
||||
return (*(*[SizeofVfRssQueryEn]byte)(unsafe.Pointer(msg)))[:]
|
||||
}
|
||||
|
||||
// struct ifla_vf_trust {
|
||||
// __u32 vf;
|
||||
// __u32 setting;
|
||||
// };
|
||||
|
||||
type VfTrust struct {
|
||||
Vf uint32
|
||||
Setting uint32
|
||||
}
|
||||
|
||||
func (msg *VfTrust) Len() int {
|
||||
return SizeofVfTrust
|
||||
}
|
||||
|
||||
func DeserializeVfTrust(b []byte) *VfTrust {
|
||||
return (*VfTrust)(unsafe.Pointer(&b[0:SizeofVfTrust][0]))
|
||||
}
|
||||
|
||||
func (msg *VfTrust) Serialize() []byte {
|
||||
return (*(*[SizeofVfTrust]byte)(unsafe.Pointer(msg)))[:]
|
||||
}
|
||||
|
||||
const (
|
||||
IFLA_XDP_UNSPEC = iota
|
||||
IFLA_XDP_FD /* fd of xdp program to attach, or -1 to remove */
|
||||
|
Loading…
Reference in New Issue
Block a user