本文整理汇总了Golang中github.com/vishvananda/netlink.Handle.LinkSetHairpin方法的典型用法代码示例。如果您正苦于以下问题:Golang Handle.LinkSetHairpin方法的具体用法?Golang Handle.LinkSetHairpin怎么用?Golang Handle.LinkSetHairpin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vishvananda/netlink.Handle
的用法示例。
在下文中一共展示了Handle.LinkSetHairpin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setHairpinMode
func setHairpinMode(nlh *netlink.Handle, link netlink.Link, enable bool) error {
err := nlh.LinkSetHairpin(link, enable)
if err != nil && err != syscall.EINVAL {
// If error is not EINVAL something else went wrong, bail out right away
return fmt.Errorf("unable to set hairpin mode on %s via netlink: %v",
link.Attrs().Name, err)
}
// Hairpin mode successfully set up
if err == nil {
return nil
}
// The netlink method failed with EINVAL which is probably because of an older
// kernel. Try one more time via the sysfs method.
path := filepath.Join("/sys/class/net", link.Attrs().Name, "brport/hairpin_mode")
var val []byte
if enable {
val = []byte{'1', '\n'}
} else {
val = []byte{'0', '\n'}
}
if err := ioutil.WriteFile(path, val, 0644); err != nil {
return fmt.Errorf("unable to set hairpin mode on %s via sysfs: %v", link.Attrs().Name, err)
}
return nil
}