repo
stringlengths
5
67
sha
stringlengths
40
40
path
stringlengths
4
234
url
stringlengths
85
339
language
stringclasses
6 values
split
stringclasses
3 values
doc
stringlengths
3
51.2k
sign
stringlengths
5
8.01k
problem
stringlengths
13
51.2k
output
stringlengths
0
3.87M
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
class_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class_linux.go#L196-L198
go
train
// ClassList gets a list of classes in the system. // Equivalent to: `tc class show`. // Generally returns nothing if link and parent are not specified.
func ClassList(link Link, parent uint32) ([]Class, error)
// ClassList gets a list of classes in the system. // Equivalent to: `tc class show`. // Generally returns nothing if link and parent are not specified. func ClassList(link Link, parent uint32) ([]Class, error)
{ return pkgHandle.ClassList(link, parent) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
class_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class_linux.go#L203-L290
go
train
// ClassList gets a list of classes in the system. // Equivalent to: `tc class show`. // Generally returns nothing if link and parent are not specified.
func (h *Handle) ClassList(link Link, parent uint32) ([]Class, error)
// ClassList gets a list of classes in the system. // Equivalent to: `tc class show`. // Generally returns nothing if link and parent are not specified. func (h *Handle) ClassList(link Link, parent uint32) ([]Class, error)
{ req := h.newNetlinkRequest(unix.RTM_GETTCLASS, unix.NLM_F_DUMP) msg := &nl.TcMsg{ Family: nl.FAMILY_ALL, Parent: parent, } if link != nil { base := link.Attrs() h.ensureIndex(base) msg.Ifindex = int32(base.Index) } req.AddData(msg) msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWTCLASS) if err != nil { return nil, err } var res []Class for _, m := range msgs { msg := nl.DeserializeTcMsg(m) attrs, err := nl.ParseRouteAttr(m[msg.Len():]) if err != nil { return nil, err } base := ClassAttrs{ LinkIndex: int(msg.Ifindex), Handle: msg.Handle, Parent: msg.Parent, Statistics: nil, } var class Class classType := "" for _, attr := range attrs { switch attr.Attr.Type { case nl.TCA_KIND: classType = string(attr.Value[:len(attr.Value)-1]) switch classType { case "htb": class = &HtbClass{} case "hfsc": class = &HfscClass{} default: class = &GenericClass{ClassType: classType} } case nl.TCA_OPTIONS: switch classType { case "htb": data, err := nl.ParseRouteAttr(attr.Value) if err != nil { return nil, err } _, err = parseHtbClassData(class, data) if err != nil { return nil, err } case "hfsc": data, err := nl.ParseRouteAttr(attr.Value) if err != nil { return nil, err } _, err = parseHfscClassData(class, data) if err != nil { return nil, err } } // For backward compatibility. case nl.TCA_STATS: base.Statistics, err = parseTcStats(attr.Value) if err != nil { return nil, err } case nl.TCA_STATS2: base.Statistics, err = parseTcStats2(attr.Value) if err != nil { return nil, err } } } *class.Attrs() = base res = append(res, class) } return res, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L37-L45
go
train
// GetIPFamily returns the family type of a net.IP.
func GetIPFamily(ip net.IP) int
// GetIPFamily returns the family type of a net.IP. func GetIPFamily(ip net.IP) int
{ if len(ip) <= net.IPv4len { return FAMILY_V4 } if ip.To4() != nil { return FAMILY_V4 } return FAMILY_V6 }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L63-L68
go
train
// Byte swap a 16 bit value if we aren't big endian
func Swap16(i uint16) uint16
// Byte swap a 16 bit value if we aren't big endian func Swap16(i uint16) uint16
{ if NativeEndian() == binary.BigEndian { return i } return (i&0xff00)>>8 | (i&0xff)<<8 }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L71-L76
go
train
// Byte swap a 32 bit value if aren't big endian
func Swap32(i uint32) uint32
// Byte swap a 32 bit value if aren't big endian func Swap32(i uint32) uint32
{ if NativeEndian() == binary.BigEndian { return i } return (i&0xff000000)>>24 | (i&0xff0000)>>8 | (i&0xff00)<<8 | (i&0xff)<<24 }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L89-L95
go
train
// Create an IfInfomsg with family specified
func NewIfInfomsg(family int) *IfInfomsg
// Create an IfInfomsg with family specified func NewIfInfomsg(family int) *IfInfomsg
{ return &IfInfomsg{ IfInfomsg: unix.IfInfomsg{ Family: uint8(family), }, } }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L268-L276
go
train
// Create a new Extended RtAttr object
func NewRtAttr(attrType int, data []byte) *RtAttr
// Create a new Extended RtAttr object func NewRtAttr(attrType int, data []byte) *RtAttr
{ return &RtAttr{ RtAttr: unix.RtAttr{ Type: uint16(attrType), }, children: []NetlinkRequestData{}, Data: data, } }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L281-L283
go
train
// NewRtAttrChild adds an RtAttr as a child to the parent and returns the new attribute // // Deprecated: Use AddRtAttr() on the parent object
func NewRtAttrChild(parent *RtAttr, attrType int, data []byte) *RtAttr
// NewRtAttrChild adds an RtAttr as a child to the parent and returns the new attribute // // Deprecated: Use AddRtAttr() on the parent object func NewRtAttrChild(parent *RtAttr, attrType int, data []byte) *RtAttr
{ return parent.AddRtAttr(attrType, data) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L286-L290
go
train
// AddRtAttr adds an RtAttr as a child and returns the new attribute
func (a *RtAttr) AddRtAttr(attrType int, data []byte) *RtAttr
// AddRtAttr adds an RtAttr as a child and returns the new attribute func (a *RtAttr) AddRtAttr(attrType int, data []byte) *RtAttr
{ attr := NewRtAttr(attrType, data) a.children = append(a.children, attr) return attr }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L293-L295
go
train
// AddChild adds an existing NetlinkRequestData as a child.
func (a *RtAttr) AddChild(attr NetlinkRequestData)
// AddChild adds an existing NetlinkRequestData as a child. func (a *RtAttr) AddChild(attr NetlinkRequestData)
{ a.children = append(a.children, attr) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L346-L371
go
train
// Serialize the Netlink Request into a byte array
func (req *NetlinkRequest) Serialize() []byte
// Serialize the Netlink Request into a byte array func (req *NetlinkRequest) Serialize() []byte
{ length := unix.SizeofNlMsghdr dataBytes := make([][]byte, len(req.Data)) for i, data := range req.Data { dataBytes[i] = data.Serialize() length = length + len(dataBytes[i]) } length += len(req.RawData) req.Len = uint32(length) b := make([]byte, length) hdr := (*(*[unix.SizeofNlMsghdr]byte)(unsafe.Pointer(req)))[:] next := unix.SizeofNlMsghdr copy(b[0:next], hdr) for _, data := range dataBytes { for _, dataByte := range data { b[next] = dataByte next = next + 1 } } // Add the raw data if any if len(req.RawData) > 0 { copy(b[next:length], req.RawData) } return b }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L378-L380
go
train
// AddRawData adds raw bytes to the end of the NetlinkRequest object during serialization
func (req *NetlinkRequest) AddRawData(data []byte)
// AddRawData adds raw bytes to the end of the NetlinkRequest object during serialization func (req *NetlinkRequest) AddRawData(data []byte)
{ req.RawData = append(req.RawData, data...) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L385-L458
go
train
// Execute the request against a the given sockType. // Returns a list of netlink messages in serialized format, optionally filtered // by resType.
func (req *NetlinkRequest) Execute(sockType int, resType uint16) ([][]byte, error)
// Execute the request against a the given sockType. // Returns a list of netlink messages in serialized format, optionally filtered // by resType. func (req *NetlinkRequest) Execute(sockType int, resType uint16) ([][]byte, error)
{ var ( s *NetlinkSocket err error ) if req.Sockets != nil { if sh, ok := req.Sockets[sockType]; ok { s = sh.Socket req.Seq = atomic.AddUint32(&sh.Seq, 1) } } sharedSocket := s != nil if s == nil { s, err = getNetlinkSocket(sockType) if err != nil { return nil, err } defer s.Close() } else { s.Lock() defer s.Unlock() } if err := s.Send(req); err != nil { return nil, err } pid, err := s.GetPid() if err != nil { return nil, err } var res [][]byte done: for { msgs, err := s.Receive() if err != nil { return nil, err } for _, m := range msgs { if m.Header.Seq != req.Seq { if sharedSocket { continue } return nil, fmt.Errorf("Wrong Seq nr %d, expected %d", m.Header.Seq, req.Seq) } if m.Header.Pid != pid { return nil, fmt.Errorf("Wrong pid %d, expected %d", m.Header.Pid, pid) } if m.Header.Type == unix.NLMSG_DONE { break done } if m.Header.Type == unix.NLMSG_ERROR { native := NativeEndian() error := int32(native.Uint32(m.Data[0:4])) if error == 0 { break done } return nil, syscall.Errno(-error) } if resType != 0 && m.Header.Type != resType { continue } res = append(res, m.Data) if m.Header.Flags&unix.NLM_F_MULTI == 0 { break done } } } return res, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L463-L472
go
train
// Create a new netlink request from proto and flags // Note the Len value will be inaccurate once data is added until // the message is serialized
func NewNetlinkRequest(proto, flags int) *NetlinkRequest
// Create a new netlink request from proto and flags // Note the Len value will be inaccurate once data is added until // the message is serialized func NewNetlinkRequest(proto, flags int) *NetlinkRequest
{ return &NetlinkRequest{ NlMsghdr: unix.NlMsghdr{ Len: uint32(unix.SizeofNlMsghdr), Type: uint16(proto), Flags: unix.NLM_F_REQUEST | uint16(flags), Seq: atomic.AddUint32(&nextSeqNr, 1), }, } }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L502-L509
go
train
// GetNetlinkSocketAt opens a netlink socket in the network namespace newNs // and positions the thread back into the network namespace specified by curNs, // when done. If curNs is close, the function derives the current namespace and // moves back into it when done. If newNs is close, the socket will be opened // in the current network namespace.
func GetNetlinkSocketAt(newNs, curNs netns.NsHandle, protocol int) (*NetlinkSocket, error)
// GetNetlinkSocketAt opens a netlink socket in the network namespace newNs // and positions the thread back into the network namespace specified by curNs, // when done. If curNs is close, the function derives the current namespace and // moves back into it when done. If newNs is close, the socket will be opened // in the current network namespace. func GetNetlinkSocketAt(newNs, curNs netns.NsHandle, protocol int) (*NetlinkSocket, error)
{ c, err := executeInNetns(newNs, curNs) if err != nil { return nil, err } defer c() return getNetlinkSocket(protocol) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L524-L560
go
train
// executeInNetns sets execution of the code following this call to the // network namespace newNs, then moves the thread back to curNs if open, // otherwise to the current netns at the time the function was invoked // In case of success, the caller is expected to execute the returned function // at the end of the code that needs to be executed in the network namespace. // Example: // func jobAt(...) error { // d, err := executeInNetns(...) // if err != nil { return err} // defer d() // < code which needs to be executed in specific netns> // } // TODO: his function probably belongs to netns pkg.
func executeInNetns(newNs, curNs netns.NsHandle) (func(), error)
// executeInNetns sets execution of the code following this call to the // network namespace newNs, then moves the thread back to curNs if open, // otherwise to the current netns at the time the function was invoked // In case of success, the caller is expected to execute the returned function // at the end of the code that needs to be executed in the network namespace. // Example: // func jobAt(...) error { // d, err := executeInNetns(...) // if err != nil { return err} // defer d() // < code which needs to be executed in specific netns> // } // TODO: his function probably belongs to netns pkg. func executeInNetns(newNs, curNs netns.NsHandle) (func(), error)
{ var ( err error moveBack func(netns.NsHandle) error closeNs func() error unlockThd func() ) restore := func() { // order matters if moveBack != nil { moveBack(curNs) } if closeNs != nil { closeNs() } if unlockThd != nil { unlockThd() } } if newNs.IsOpen() { runtime.LockOSThread() unlockThd = runtime.UnlockOSThread if !curNs.IsOpen() { if curNs, err = netns.Get(); err != nil { restore() return nil, fmt.Errorf("could not get current namespace while creating netlink socket: %v", err) } closeNs = curNs.Close } if err := netns.Set(newNs); err != nil { restore() return nil, fmt.Errorf("failed to set into network namespace %d while creating netlink socket: %v", newNs, err) } moveBack = netns.Set } return restore, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L566-L586
go
train
// Create a netlink socket with a given protocol (e.g. NETLINK_ROUTE) // and subscribe it to multicast groups passed in variable argument list. // Returns the netlink socket on which Receive() method can be called // to retrieve the messages from the kernel.
func Subscribe(protocol int, groups ...uint) (*NetlinkSocket, error)
// Create a netlink socket with a given protocol (e.g. NETLINK_ROUTE) // and subscribe it to multicast groups passed in variable argument list. // Returns the netlink socket on which Receive() method can be called // to retrieve the messages from the kernel. func Subscribe(protocol int, groups ...uint) (*NetlinkSocket, error)
{ fd, err := unix.Socket(unix.AF_NETLINK, unix.SOCK_RAW, protocol) if err != nil { return nil, err } s := &NetlinkSocket{ fd: int32(fd), } s.lsa.Family = unix.AF_NETLINK for _, g := range groups { s.lsa.Groups |= (1 << (g - 1)) } if err := unix.Bind(fd, &s.lsa); err != nil { unix.Close(fd) return nil, err } return s, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L591-L598
go
train
// SubscribeAt works like Subscribe plus let's the caller choose the network // namespace in which the socket would be opened (newNs). Then control goes back // to curNs if open, otherwise to the netns at the time this function was called.
func SubscribeAt(newNs, curNs netns.NsHandle, protocol int, groups ...uint) (*NetlinkSocket, error)
// SubscribeAt works like Subscribe plus let's the caller choose the network // namespace in which the socket would be opened (newNs). Then control goes back // to curNs if open, otherwise to the netns at the time this function was called. func SubscribeAt(newNs, curNs netns.NsHandle, protocol int, groups ...uint) (*NetlinkSocket, error)
{ c, err := executeInNetns(newNs, curNs) if err != nil { return nil, err } defer c() return Subscribe(protocol, groups...) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L639-L643
go
train
// SetSendTimeout allows to set a send timeout on the socket
func (s *NetlinkSocket) SetSendTimeout(timeout *unix.Timeval) error
// SetSendTimeout allows to set a send timeout on the socket func (s *NetlinkSocket) SetSendTimeout(timeout *unix.Timeval) error
{ // Set a send timeout of SOCKET_SEND_TIMEOUT, this will allow the Send to periodically unblock and avoid that a routine // remains stuck on a send on a closed fd return unix.SetsockoptTimeval(int(s.fd), unix.SOL_SOCKET, unix.SO_SNDTIMEO, timeout) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/nl_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L646-L650
go
train
// SetReceiveTimeout allows to set a receive timeout on the socket
func (s *NetlinkSocket) SetReceiveTimeout(timeout *unix.Timeval) error
// SetReceiveTimeout allows to set a receive timeout on the socket func (s *NetlinkSocket) SetReceiveTimeout(timeout *unix.Timeval) error
{ // Set a read timeout of SOCKET_READ_TIMEOUT, this will allow the Read to periodically unblock and avoid that a routine // remains stuck on a recvmsg on a closed fd return unix.SetsockoptTimeval(int(s.fd), unix.SOL_SOCKET, unix.SO_RCVTIMEO, timeout) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_state_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_state_linux.go#L88-L90
go
train
// XfrmStateAdd will add an xfrm state to the system. // Equivalent to: `ip xfrm state add $state`
func (h *Handle) XfrmStateAdd(state *XfrmState) error
// XfrmStateAdd will add an xfrm state to the system. // Equivalent to: `ip xfrm state add $state` func (h *Handle) XfrmStateAdd(state *XfrmState) error
{ return h.xfrmStateAddOrUpdate(state, nl.XFRM_MSG_NEWSA) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_state_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_state_linux.go#L106-L108
go
train
// XfrmStateUpdate will update an xfrm state to the system. // Equivalent to: `ip xfrm state update $state`
func (h *Handle) XfrmStateUpdate(state *XfrmState) error
// XfrmStateUpdate will update an xfrm state to the system. // Equivalent to: `ip xfrm state update $state` func (h *Handle) XfrmStateUpdate(state *XfrmState) error
{ return h.xfrmStateAddOrUpdate(state, nl.XFRM_MSG_UPDSA) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_state_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_state_linux.go#L203-L206
go
train
// XfrmStateDel will delete an xfrm state from the system. Note that // the Algos are ignored when matching the state to delete. // Equivalent to: `ip xfrm state del $state`
func (h *Handle) XfrmStateDel(state *XfrmState) error
// XfrmStateDel will delete an xfrm state from the system. Note that // the Algos are ignored when matching the state to delete. // Equivalent to: `ip xfrm state del $state` func (h *Handle) XfrmStateDel(state *XfrmState) error
{ _, err := h.xfrmStateGetOrDelete(state, nl.XFRM_MSG_DELSA) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_state_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_state_linux.go#L218-L237
go
train
// XfrmStateList gets a list of xfrm states in the system. // Equivalent to: `ip xfrm state show`. // The list can be filtered by ip family.
func (h *Handle) XfrmStateList(family int) ([]XfrmState, error)
// XfrmStateList gets a list of xfrm states in the system. // Equivalent to: `ip xfrm state show`. // The list can be filtered by ip family. func (h *Handle) XfrmStateList(family int) ([]XfrmState, error)
{ req := h.newNetlinkRequest(nl.XFRM_MSG_GETSA, unix.NLM_F_DUMP) msgs, err := req.Execute(unix.NETLINK_XFRM, nl.XFRM_MSG_NEWSA) if err != nil { return nil, err } var res []XfrmState for _, m := range msgs { if state, err := parseXfrmState(m, family); err == nil { res = append(res, *state) } else if err == familyError { continue } else { return nil, err } } return res, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_state_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_state_linux.go#L253-L255
go
train
// XfrmStateGet gets the xfrm state described by the ID, if found. // Equivalent to: `ip xfrm state get ID [ mark MARK [ mask MASK ] ]`. // Only the fields which constitue the SA ID must be filled in: // ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ] // mark is optional
func (h *Handle) XfrmStateGet(state *XfrmState) (*XfrmState, error)
// XfrmStateGet gets the xfrm state described by the ID, if found. // Equivalent to: `ip xfrm state get ID [ mark MARK [ mask MASK ] ]`. // Only the fields which constitue the SA ID must be filled in: // ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ] // mark is optional func (h *Handle) XfrmStateGet(state *XfrmState) (*XfrmState, error)
{ return h.xfrmStateGetOrDelete(state, nl.XFRM_MSG_GETSA) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_state_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_state_linux.go#L394-L401
go
train
// XfrmStateFlush will flush the xfrm state on the system. // proto = 0 means any transformation protocols // Equivalent to: `ip xfrm state flush [ proto XFRM-PROTO ]`
func (h *Handle) XfrmStateFlush(proto Proto) error
// XfrmStateFlush will flush the xfrm state on the system. // proto = 0 means any transformation protocols // Equivalent to: `ip xfrm state flush [ proto XFRM-PROTO ]` func (h *Handle) XfrmStateFlush(proto Proto) error
{ req := h.newNetlinkRequest(nl.XFRM_MSG_FLUSHSA, unix.NLM_F_ACK) req.AddData(&nl.XfrmUsersaFlush{Proto: uint8(proto)}) _, err := req.Execute(unix.NETLINK_XFRM, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh.go#L23-L25
go
train
// String returns $ip/$hwaddr $label
func (neigh *Neigh) String() string
// String returns $ip/$hwaddr $label func (neigh *Neigh) String() string
{ return fmt.Sprintf("%s %s", neigh.IP, neigh.HardwareAddr) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L78-L80
go
train
// NeighAdd will add an IP to MAC mapping to the ARP table // Equivalent to: `ip neigh add ....`
func (h *Handle) NeighAdd(neigh *Neigh) error
// NeighAdd will add an IP to MAC mapping to the ARP table // Equivalent to: `ip neigh add ....` func (h *Handle) NeighAdd(neigh *Neigh) error
{ return h.neighAdd(neigh, unix.NLM_F_CREATE|unix.NLM_F_EXCL) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L90-L92
go
train
// NeighSet will add or replace an IP to MAC mapping to the ARP table // Equivalent to: `ip neigh replace....`
func (h *Handle) NeighSet(neigh *Neigh) error
// NeighSet will add or replace an IP to MAC mapping to the ARP table // Equivalent to: `ip neigh replace....` func (h *Handle) NeighSet(neigh *Neigh) error
{ return h.neighAdd(neigh, unix.NLM_F_CREATE|unix.NLM_F_REPLACE) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L102-L104
go
train
// NeighAppend will append an entry to FDB // Equivalent to: `bridge fdb append...`
func (h *Handle) NeighAppend(neigh *Neigh) error
// NeighAppend will append an entry to FDB // Equivalent to: `bridge fdb append...` func (h *Handle) NeighAppend(neigh *Neigh) error
{ return h.neighAdd(neigh, unix.NLM_F_CREATE|unix.NLM_F_APPEND) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L108-L110
go
train
// NeighAppend will append an entry to FDB // Equivalent to: `bridge fdb append...`
func neighAdd(neigh *Neigh, mode int) error
// NeighAppend will append an entry to FDB // Equivalent to: `bridge fdb append...` func neighAdd(neigh *Neigh, mode int) error
{ return pkgHandle.neighAdd(neigh, mode) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L114-L117
go
train
// NeighAppend will append an entry to FDB // Equivalent to: `bridge fdb append...`
func (h *Handle) neighAdd(neigh *Neigh, mode int) error
// NeighAppend will append an entry to FDB // Equivalent to: `bridge fdb append...` func (h *Handle) neighAdd(neigh *Neigh, mode int) error
{ req := h.newNetlinkRequest(unix.RTM_NEWNEIGH, mode|unix.NLM_F_ACK) return neighHandle(neigh, req) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L127-L130
go
train
// NeighDel will delete an IP address from a link device. // Equivalent to: `ip addr del $addr dev $link`
func (h *Handle) NeighDel(neigh *Neigh) error
// NeighDel will delete an IP address from a link device. // Equivalent to: `ip addr del $addr dev $link` func (h *Handle) NeighDel(neigh *Neigh) error
{ req := h.newNetlinkRequest(unix.RTM_DELNEIGH, unix.NLM_F_ACK) return neighHandle(neigh, req) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L183-L185
go
train
// NeighList returns a list of IP-MAC mappings in the system (ARP table). // Equivalent to: `ip neighbor show`. // The list can be filtered by link and ip family.
func NeighList(linkIndex, family int) ([]Neigh, error)
// NeighList returns a list of IP-MAC mappings in the system (ARP table). // Equivalent to: `ip neighbor show`. // The list can be filtered by link and ip family. func NeighList(linkIndex, family int) ([]Neigh, error)
{ return pkgHandle.NeighList(linkIndex, family) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L190-L192
go
train
// NeighProxyList returns a list of neighbor proxies in the system. // Equivalent to: `ip neighbor show proxy`. // The list can be filtered by link and ip family.
func NeighProxyList(linkIndex, family int) ([]Neigh, error)
// NeighProxyList returns a list of neighbor proxies in the system. // Equivalent to: `ip neighbor show proxy`. // The list can be filtered by link and ip family. func NeighProxyList(linkIndex, family int) ([]Neigh, error)
{ return pkgHandle.NeighProxyList(linkIndex, family) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L197-L202
go
train
// NeighList returns a list of IP-MAC mappings in the system (ARP table). // Equivalent to: `ip neighbor show`. // The list can be filtered by link and ip family.
func (h *Handle) NeighList(linkIndex, family int) ([]Neigh, error)
// NeighList returns a list of IP-MAC mappings in the system (ARP table). // Equivalent to: `ip neighbor show`. // The list can be filtered by link and ip family. func (h *Handle) NeighList(linkIndex, family int) ([]Neigh, error)
{ return h.NeighListExecute(Ndmsg{ Family: uint8(family), Index: uint32(linkIndex), }) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L207-L213
go
train
// NeighProxyList returns a list of neighbor proxies in the system. // Equivalent to: `ip neighbor show proxy`. // The list can be filtered by link, ip family.
func (h *Handle) NeighProxyList(linkIndex, family int) ([]Neigh, error)
// NeighProxyList returns a list of neighbor proxies in the system. // Equivalent to: `ip neighbor show proxy`. // The list can be filtered by link, ip family. func (h *Handle) NeighProxyList(linkIndex, family int) ([]Neigh, error)
{ return h.NeighListExecute(Ndmsg{ Family: uint8(family), Index: uint32(linkIndex), Flags: NTF_PROXY, }) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L221-L247
go
train
// NeighListExecute returns a list of neighbour entries filtered by link, ip family, flag and state.
func (h *Handle) NeighListExecute(msg Ndmsg) ([]Neigh, error)
// NeighListExecute returns a list of neighbour entries filtered by link, ip family, flag and state. func (h *Handle) NeighListExecute(msg Ndmsg) ([]Neigh, error)
{ req := h.newNetlinkRequest(unix.RTM_GETNEIGH, unix.NLM_F_DUMP) req.AddData(&msg) msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNEIGH) if err != nil { return nil, err } var res []Neigh for _, m := range msgs { ndm := deserializeNdmsg(m) if msg.Index != 0 && ndm.Index != msg.Index { // Ignore messages from other interfaces continue } neigh, err := NeighDeserialize(m) if err != nil { continue } res = append(res, *neigh) } return res, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L299-L301
go
train
// NeighSubscribe takes a chan down which notifications will be sent // when neighbors are added or deleted. Close the 'done' chan to stop subscription.
func NeighSubscribe(ch chan<- NeighUpdate, done <-chan struct{}) error
// NeighSubscribe takes a chan down which notifications will be sent // when neighbors are added or deleted. Close the 'done' chan to stop subscription. func NeighSubscribe(ch chan<- NeighUpdate, done <-chan struct{}) error
{ return neighSubscribeAt(netns.None(), netns.None(), ch, done, nil, false) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L305-L307
go
train
// NeighSubscribeAt works like NeighSubscribe plus it allows the caller // to choose the network namespace in which to subscribe (ns).
func NeighSubscribeAt(ns netns.NsHandle, ch chan<- NeighUpdate, done <-chan struct{}) error
// NeighSubscribeAt works like NeighSubscribe plus it allows the caller // to choose the network namespace in which to subscribe (ns). func NeighSubscribeAt(ns netns.NsHandle, ch chan<- NeighUpdate, done <-chan struct{}) error
{ return neighSubscribeAt(ns, netns.None(), ch, done, nil, false) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
neigh_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L320-L326
go
train
// NeighSubscribeWithOptions work like NeighSubscribe but enable to // provide additional options to modify the behavior. Currently, the // namespace can be provided as well as an error callback.
func NeighSubscribeWithOptions(ch chan<- NeighUpdate, done <-chan struct{}, options NeighSubscribeOptions) error
// NeighSubscribeWithOptions work like NeighSubscribe but enable to // provide additional options to modify the behavior. Currently, the // namespace can be provided as well as an error callback. func NeighSubscribeWithOptions(ch chan<- NeighUpdate, done <-chan struct{}, options NeighSubscribeOptions) error
{ if options.Namespace == nil { none := netns.None() options.Namespace = &none } return neighSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
conntrack_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L50-L52
go
train
// -L [table] [options] List conntrack or expectation table // -G [table] parameters Get conntrack or expectation // -I [table] parameters Create a conntrack or expectation // -U [table] parameters Update a conntrack // -E [table] [options] Show events // -C [table] Show counter // -S Show statistics // ConntrackTableList returns the flow list of a table of a specific family // conntrack -L [table] [options] List conntrack or expectation table
func ConntrackTableList(table ConntrackTableType, family InetFamily) ([]*ConntrackFlow, error)
// -L [table] [options] List conntrack or expectation table // -G [table] parameters Get conntrack or expectation // -I [table] parameters Create a conntrack or expectation // -U [table] parameters Update a conntrack // -E [table] [options] Show events // -C [table] Show counter // -S Show statistics // ConntrackTableList returns the flow list of a table of a specific family // conntrack -L [table] [options] List conntrack or expectation table func ConntrackTableList(table ConntrackTableType, family InetFamily) ([]*ConntrackFlow, error)
{ return pkgHandle.ConntrackTableList(table, family) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
conntrack_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L63-L65
go
train
// ConntrackDeleteFilter deletes entries on the specified table on the base of the filter // conntrack -D [table] parameters Delete conntrack or expectation
func ConntrackDeleteFilter(table ConntrackTableType, family InetFamily, filter CustomConntrackFilter) (uint, error)
// ConntrackDeleteFilter deletes entries on the specified table on the base of the filter // conntrack -D [table] parameters Delete conntrack or expectation func ConntrackDeleteFilter(table ConntrackTableType, family InetFamily, filter CustomConntrackFilter) (uint, error)
{ return pkgHandle.ConntrackDeleteFilter(table, family, filter) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
conntrack_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L69-L82
go
train
// ConntrackTableList returns the flow list of a table of a specific family using the netlink handle passed // conntrack -L [table] [options] List conntrack or expectation table
func (h *Handle) ConntrackTableList(table ConntrackTableType, family InetFamily) ([]*ConntrackFlow, error)
// ConntrackTableList returns the flow list of a table of a specific family using the netlink handle passed // conntrack -L [table] [options] List conntrack or expectation table func (h *Handle) ConntrackTableList(table ConntrackTableType, family InetFamily) ([]*ConntrackFlow, error)
{ res, err := h.dumpConntrackTable(table, family) if err != nil { return nil, err } // Deserialize all the flows var result []*ConntrackFlow for _, dataRaw := range res { result = append(result, parseRawData(dataRaw)) } return result, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
conntrack_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L87-L91
go
train
// ConntrackTableFlush flushes all the flows of a specified table using the netlink handle passed // conntrack -F [table] Flush table // The flush operation applies to all the family types
func (h *Handle) ConntrackTableFlush(table ConntrackTableType) error
// ConntrackTableFlush flushes all the flows of a specified table using the netlink handle passed // conntrack -F [table] Flush table // The flush operation applies to all the family types func (h *Handle) ConntrackTableFlush(table ConntrackTableType) error
{ req := h.newConntrackRequest(table, unix.AF_INET, nl.IPCTNL_MSG_CT_DELETE, unix.NLM_F_ACK) _, err := req.Execute(unix.NETLINK_NETFILTER, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
conntrack_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L95-L114
go
train
// ConntrackDeleteFilter deletes entries on the specified table on the base of the filter using the netlink handle passed // conntrack -D [table] parameters Delete conntrack or expectation
func (h *Handle) ConntrackDeleteFilter(table ConntrackTableType, family InetFamily, filter CustomConntrackFilter) (uint, error)
// ConntrackDeleteFilter deletes entries on the specified table on the base of the filter using the netlink handle passed // conntrack -D [table] parameters Delete conntrack or expectation func (h *Handle) ConntrackDeleteFilter(table ConntrackTableType, family InetFamily, filter CustomConntrackFilter) (uint, error)
{ res, err := h.dumpConntrackTable(table, family) if err != nil { return 0, err } var matched uint for _, dataRaw := range res { flow := parseRawData(dataRaw) if match := filter.MatchConntrackFlow(flow); match { req2 := h.newConntrackRequest(table, family, nl.IPCTNL_MSG_CT_DELETE, unix.NLM_F_ACK) // skip the first 4 byte that are the netfilter header, the newConntrackRequest is adding it already req2.AddRawData(dataRaw[4:]) req2.Execute(unix.NETLINK_NETFILTER, 0) matched++ } } return matched, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
conntrack_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L171-L201
go
train
// This method parse the ip tuple structure // The message structure is the following: // <len, [CTA_IP_V4_SRC|CTA_IP_V6_SRC], 16 bytes for the IP> // <len, [CTA_IP_V4_DST|CTA_IP_V6_DST], 16 bytes for the IP> // <len, NLA_F_NESTED|nl.CTA_TUPLE_PROTO, 1 byte for the protocol, 3 bytes of padding> // <len, CTA_PROTO_SRC_PORT, 2 bytes for the source port, 2 bytes of padding> // <len, CTA_PROTO_DST_PORT, 2 bytes for the source port, 2 bytes of padding>
func parseIpTuple(reader *bytes.Reader, tpl *ipTuple) uint8
// This method parse the ip tuple structure // The message structure is the following: // <len, [CTA_IP_V4_SRC|CTA_IP_V6_SRC], 16 bytes for the IP> // <len, [CTA_IP_V4_DST|CTA_IP_V6_DST], 16 bytes for the IP> // <len, NLA_F_NESTED|nl.CTA_TUPLE_PROTO, 1 byte for the protocol, 3 bytes of padding> // <len, CTA_PROTO_SRC_PORT, 2 bytes for the source port, 2 bytes of padding> // <len, CTA_PROTO_DST_PORT, 2 bytes for the source port, 2 bytes of padding> func parseIpTuple(reader *bytes.Reader, tpl *ipTuple) uint8
{ for i := 0; i < 2; i++ { _, t, _, v := parseNfAttrTLV(reader) switch t { case nl.CTA_IP_V4_SRC, nl.CTA_IP_V6_SRC: tpl.SrcIP = v case nl.CTA_IP_V4_DST, nl.CTA_IP_V6_DST: tpl.DstIP = v } } // Skip the next 4 bytes nl.NLA_F_NESTED|nl.CTA_TUPLE_PROTO reader.Seek(4, seekCurrent) _, t, _, v := parseNfAttrTLV(reader) if t == nl.CTA_PROTO_NUM { tpl.Protocol = uint8(v[0]) } // Skip some padding 3 bytes reader.Seek(3, seekCurrent) for i := 0; i < 2; i++ { _, t, _ := parseNfAttrTL(reader) switch t { case nl.CTA_PROTO_SRC_PORT: parseBERaw16(reader, &tpl.SrcPort) case nl.CTA_PROTO_DST_PORT: parseBERaw16(reader, &tpl.DstPort) } // Skip some padding 2 byte reader.Seek(2, seekCurrent) } return tpl.Protocol }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
conntrack_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L350-L359
go
train
// AddIP adds an IP to the conntrack filter
func (f *ConntrackFilter) AddIP(tp ConntrackFilterType, ip net.IP) error
// AddIP adds an IP to the conntrack filter func (f *ConntrackFilter) AddIP(tp ConntrackFilterType, ip net.IP) error
{ if f.ipFilter == nil { f.ipFilter = make(map[ConntrackFilterType]net.IP) } if _, ok := f.ipFilter[tp]; ok { return errors.New("Filter attribute already present") } f.ipFilter[tp] = ip return nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
conntrack_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L363-L396
go
train
// MatchConntrackFlow applies the filter to the flow and returns true if the flow matches the filter // false otherwise
func (f *ConntrackFilter) MatchConntrackFlow(flow *ConntrackFlow) bool
// MatchConntrackFlow applies the filter to the flow and returns true if the flow matches the filter // false otherwise func (f *ConntrackFilter) MatchConntrackFlow(flow *ConntrackFlow) bool
{ if len(f.ipFilter) == 0 { // empty filter always not match return false } match := true // -orig-src ip Source address from original direction if elem, found := f.ipFilter[ConntrackOrigSrcIP]; found { match = match && elem.Equal(flow.Forward.SrcIP) } // -orig-dst ip Destination address from original direction if elem, found := f.ipFilter[ConntrackOrigDstIP]; match && found { match = match && elem.Equal(flow.Forward.DstIP) } // -src-nat ip Source NAT ip if elem, found := f.ipFilter[ConntrackReplySrcIP]; match && found { match = match && elem.Equal(flow.Reverse.SrcIP) } // -dst-nat ip Destination NAT ip if elem, found := f.ipFilter[ConntrackReplyDstIP]; match && found { match = match && elem.Equal(flow.Reverse.DstIP) } // Match source or destination reply IP if elem, found := f.ipFilter[ConntrackReplyAnyIP]; match && found { match = match && (elem.Equal(flow.Reverse.SrcIP) || elem.Equal(flow.Reverse.DstIP)) } return match }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
protinfo.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/protinfo.go#L20-L51
go
train
// String returns a list of enabled flags
func (prot *Protinfo) String() string
// String returns a list of enabled flags func (prot *Protinfo) String() string
{ if prot == nil { return "<nil>" } var boolStrings []string if prot.Hairpin { boolStrings = append(boolStrings, "Hairpin") } if prot.Guard { boolStrings = append(boolStrings, "Guard") } if prot.FastLeave { boolStrings = append(boolStrings, "FastLeave") } if prot.RootBlock { boolStrings = append(boolStrings, "RootBlock") } if prot.Learning { boolStrings = append(boolStrings, "Learning") } if prot.Flood { boolStrings = append(boolStrings, "Flood") } if prot.ProxyArp { boolStrings = append(boolStrings, "ProxyArp") } if prot.ProxyArpWiFi { boolStrings = append(boolStrings, "ProxyArpWiFi") } return strings.Join(boolStrings, " ") }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
class.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L143-L145
go
train
// Attrs return the parameters of the service curve
func (c *ServiceCurve) Attrs() (uint32, uint32, uint32)
// Attrs return the parameters of the service curve func (c *ServiceCurve) Attrs() (uint32, uint32, uint32)
{ return c.m1, c.d, c.m2 }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
class.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L166-L168
go
train
// SetRsc sets the Rsc curve
func (hfsc *HfscClass) SetRsc(m1 uint32, d uint32, m2 uint32)
// SetRsc sets the Rsc curve func (hfsc *HfscClass) SetRsc(m1 uint32, d uint32, m2 uint32)
{ hfsc.Rsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
class.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L171-L174
go
train
// SetSC implements the SC from the tc CLI
func (hfsc *HfscClass) SetSC(m1 uint32, d uint32, m2 uint32)
// SetSC implements the SC from the tc CLI func (hfsc *HfscClass) SetSC(m1 uint32, d uint32, m2 uint32)
{ hfsc.Rsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} hfsc.Fsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
class.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L177-L179
go
train
// SetUL implements the UL from the tc CLI
func (hfsc *HfscClass) SetUL(m1 uint32, d uint32, m2 uint32)
// SetUL implements the UL from the tc CLI func (hfsc *HfscClass) SetUL(m1 uint32, d uint32, m2 uint32)
{ hfsc.Usc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
class.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L182-L184
go
train
// SetLS implements the LS from the tc CLI
func (hfsc *HfscClass) SetLS(m1 uint32, d uint32, m2 uint32)
// SetLS implements the LS from the tc CLI func (hfsc *HfscClass) SetLS(m1 uint32, d uint32, m2 uint32)
{ hfsc.Fsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
class.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L187-L194
go
train
// NewHfscClass returns a new HFSC struct with the set parameters
func NewHfscClass(attrs ClassAttrs) *HfscClass
// NewHfscClass returns a new HFSC struct with the set parameters func NewHfscClass(attrs ClassAttrs) *HfscClass
{ return &HfscClass{ ClassAttrs: attrs, Rsc: ServiceCurve{}, Fsc: ServiceCurve{}, Usc: ServiceCurve{}, } }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
rule_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/rule_linux.go#L21-L24
go
train
// RuleAdd adds a rule to the system. // Equivalent to: ip rule add
func (h *Handle) RuleAdd(rule *Rule) error
// RuleAdd adds a rule to the system. // Equivalent to: ip rule add func (h *Handle) RuleAdd(rule *Rule) error
{ req := h.newNetlinkRequest(unix.RTM_NEWRULE, unix.NLM_F_CREATE|unix.NLM_F_EXCL|unix.NLM_F_ACK) return ruleHandle(rule, req) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
rule_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/rule_linux.go#L34-L37
go
train
// RuleDel deletes a rule from the system. // Equivalent to: ip rule del
func (h *Handle) RuleDel(rule *Rule) error
// RuleDel deletes a rule from the system. // Equivalent to: ip rule del func (h *Handle) RuleDel(rule *Rule) error
{ req := h.newNetlinkRequest(unix.RTM_DELRULE, unix.NLM_F_ACK) return ruleHandle(rule, req) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
rule_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/rule_linux.go#L165-L234
go
train
// RuleList lists rules in the system. // Equivalent to: ip rule list
func (h *Handle) RuleList(family int) ([]Rule, error)
// RuleList lists rules in the system. // Equivalent to: ip rule list func (h *Handle) RuleList(family int) ([]Rule, error)
{ req := h.newNetlinkRequest(unix.RTM_GETRULE, unix.NLM_F_DUMP|unix.NLM_F_REQUEST) msg := nl.NewIfInfomsg(family) req.AddData(msg) msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWRULE) if err != nil { return nil, err } native := nl.NativeEndian() var res = make([]Rule, 0) for i := range msgs { msg := nl.DeserializeRtMsg(msgs[i]) attrs, err := nl.ParseRouteAttr(msgs[i][msg.Len():]) if err != nil { return nil, err } rule := NewRule() rule.Invert = msg.Flags&FibRuleInvert > 0 for j := range attrs { switch attrs[j].Attr.Type { case unix.RTA_TABLE: rule.Table = int(native.Uint32(attrs[j].Value[0:4])) case nl.FRA_SRC: rule.Src = &net.IPNet{ IP: attrs[j].Value, Mask: net.CIDRMask(int(msg.Src_len), 8*len(attrs[j].Value)), } case nl.FRA_DST: rule.Dst = &net.IPNet{ IP: attrs[j].Value, Mask: net.CIDRMask(int(msg.Dst_len), 8*len(attrs[j].Value)), } case nl.FRA_FWMARK: rule.Mark = int(native.Uint32(attrs[j].Value[0:4])) case nl.FRA_FWMASK: rule.Mask = int(native.Uint32(attrs[j].Value[0:4])) case nl.FRA_TUN_ID: rule.TunID = uint(native.Uint64(attrs[j].Value[0:4])) case nl.FRA_IIFNAME: rule.IifName = string(attrs[j].Value[:len(attrs[j].Value)-1]) case nl.FRA_OIFNAME: rule.OifName = string(attrs[j].Value[:len(attrs[j].Value)-1]) case nl.FRA_SUPPRESS_PREFIXLEN: i := native.Uint32(attrs[j].Value[0:4]) if i != 0xffffffff { rule.SuppressPrefixlen = int(i) } case nl.FRA_SUPPRESS_IFGROUP: i := native.Uint32(attrs[j].Value[0:4]) if i != 0xffffffff { rule.SuppressIfgroup = int(i) } case nl.FRA_FLOW: rule.Flow = int(native.Uint32(attrs[j].Value[0:4])) case nl.FRA_GOTO: rule.Goto = int(native.Uint32(attrs[j].Value[0:4])) case nl.FRA_PRIORITY: rule.Priority = int(native.Uint32(attrs[j].Value[0:4])) } } res = append(res, *rule) } return res, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L420-L426
go
train
// StringToBondMode returns bond mode, or uknonw is the s is invalid.
func StringToBondMode(s string) BondMode
// StringToBondMode returns bond mode, or uknonw is the s is invalid. func StringToBondMode(s string) BondMode
{ mode, ok := StringToBondModeMap[s] if !ok { return BOND_MODE_UNKNOWN } return mode }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L511-L517
go
train
// StringToBondXmitHashPolicy returns bond lacp arte, or uknonw is the s is invalid.
func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy
// StringToBondXmitHashPolicy returns bond lacp arte, or uknonw is the s is invalid. func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy
{ lacp, ok := StringToBondXmitHashPolicyMap[s] if !ok { return BOND_XMIT_HASH_POLICY_UNKNOWN } return lacp }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L556-L562
go
train
// StringToBondLacpRate returns bond lacp arte, or uknonw is the s is invalid.
func StringToBondLacpRate(s string) BondLacpRate
// StringToBondLacpRate returns bond lacp arte, or uknonw is the s is invalid. func StringToBondLacpRate(s string) BondLacpRate
{ lacp, ok := StringToBondLacpRateMap[s] if !ok { return BOND_LACP_RATE_UNKNOWN } return lacp }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_policy_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_policy_linux.go#L41-L43
go
train
// XfrmPolicyAdd will add an xfrm policy to the system. // Equivalent to: `ip xfrm policy add $policy`
func (h *Handle) XfrmPolicyAdd(policy *XfrmPolicy) error
// XfrmPolicyAdd will add an xfrm policy to the system. // Equivalent to: `ip xfrm policy add $policy` func (h *Handle) XfrmPolicyAdd(policy *XfrmPolicy) error
{ return h.xfrmPolicyAddOrUpdate(policy, nl.XFRM_MSG_NEWPOLICY) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_policy_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_policy_linux.go#L53-L55
go
train
// XfrmPolicyUpdate will update an xfrm policy to the system. // Equivalent to: `ip xfrm policy update $policy`
func (h *Handle) XfrmPolicyUpdate(policy *XfrmPolicy) error
// XfrmPolicyUpdate will update an xfrm policy to the system. // Equivalent to: `ip xfrm policy update $policy` func (h *Handle) XfrmPolicyUpdate(policy *XfrmPolicy) error
{ return h.xfrmPolicyAddOrUpdate(policy, nl.XFRM_MSG_UPDPOLICY) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_policy_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_policy_linux.go#L112-L115
go
train
// XfrmPolicyDel will delete an xfrm policy from the system. Note that // the Tmpls are ignored when matching the policy to delete. // Equivalent to: `ip xfrm policy del $policy`
func (h *Handle) XfrmPolicyDel(policy *XfrmPolicy) error
// XfrmPolicyDel will delete an xfrm policy from the system. Note that // the Tmpls are ignored when matching the policy to delete. // Equivalent to: `ip xfrm policy del $policy` func (h *Handle) XfrmPolicyDel(policy *XfrmPolicy) error
{ _, err := h.xfrmPolicyGetOrDelete(policy, nl.XFRM_MSG_DELPOLICY) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_policy_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_policy_linux.go#L127-L149
go
train
// XfrmPolicyList gets a list of xfrm policies in the system. // Equivalent to: `ip xfrm policy show`. // The list can be filtered by ip family.
func (h *Handle) XfrmPolicyList(family int) ([]XfrmPolicy, error)
// XfrmPolicyList gets a list of xfrm policies in the system. // Equivalent to: `ip xfrm policy show`. // The list can be filtered by ip family. func (h *Handle) XfrmPolicyList(family int) ([]XfrmPolicy, error)
{ req := h.newNetlinkRequest(nl.XFRM_MSG_GETPOLICY, unix.NLM_F_DUMP) msg := nl.NewIfInfomsg(family) req.AddData(msg) msgs, err := req.Execute(unix.NETLINK_XFRM, nl.XFRM_MSG_NEWPOLICY) if err != nil { return nil, err } var res []XfrmPolicy for _, m := range msgs { if policy, err := parseXfrmPolicy(m, family); err == nil { res = append(res, *policy) } else if err == familyError { continue } else { return nil, err } } return res, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_policy_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_policy_linux.go#L159-L161
go
train
// XfrmPolicyGet gets a the policy described by the index or selector, if found. // Equivalent to: `ip xfrm policy get { SELECTOR | index INDEX } dir DIR [ctx CTX ] [ mark MARK [ mask MASK ] ] [ ptype PTYPE ]`.
func (h *Handle) XfrmPolicyGet(policy *XfrmPolicy) (*XfrmPolicy, error)
// XfrmPolicyGet gets a the policy described by the index or selector, if found. // Equivalent to: `ip xfrm policy get { SELECTOR | index INDEX } dir DIR [ctx CTX ] [ mark MARK [ mask MASK ] ] [ ptype PTYPE ]`. func (h *Handle) XfrmPolicyGet(policy *XfrmPolicy) (*XfrmPolicy, error)
{ return h.xfrmPolicyGetOrDelete(policy, nl.XFRM_MSG_GETPOLICY) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
xfrm_policy_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/xfrm_policy_linux.go#L171-L175
go
train
// XfrmPolicyFlush will flush the policies on the system. // Equivalent to: `ip xfrm policy flush`
func (h *Handle) XfrmPolicyFlush() error
// XfrmPolicyFlush will flush the policies on the system. // Equivalent to: `ip xfrm policy flush` func (h *Handle) XfrmPolicyFlush() error
{ req := h.newNetlinkRequest(nl.XFRM_MSG_FLUSHPOLICY, unix.NLM_F_ACK) _, err := req.Execute(unix.NETLINK_XFRM, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
nl/addr_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/addr_linux.go#L38-L40
go
train
// struct ifaddrmsg { // __u8 ifa_family; // __u8 ifa_prefixlen; /* The prefix length */ // __u8 ifa_flags; /* Flags */ // __u8 ifa_scope; /* Address scope */ // __u32 ifa_index; /* Link index */ // }; // type IfAddrmsg struct { // Family uint8 // Prefixlen uint8 // Flags uint8 // Scope uint8 // Index uint32 // } // SizeofIfAddrmsg = 0x8
func DeserializeIfAddrmsg(b []byte) *IfAddrmsg
// struct ifaddrmsg { // __u8 ifa_family; // __u8 ifa_prefixlen; /* The prefix length */ // __u8 ifa_flags; /* Flags */ // __u8 ifa_scope; /* Address scope */ // __u32 ifa_index; /* Link index */ // }; // type IfAddrmsg struct { // Family uint8 // Prefixlen uint8 // Flags uint8 // Scope uint8 // Index uint32 // } // SizeofIfAddrmsg = 0x8 func DeserializeIfAddrmsg(b []byte) *IfAddrmsg
{ return (*IfAddrmsg)(unsafe.Pointer(&b[0:unix.SizeofIfAddrmsg][0])) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
devlink_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/devlink_linux.go#L148-L172
go
train
// DevLinkGetDeviceList provides a pointer to devlink devices and nil error, // otherwise returns an error code.
func (h *Handle) DevLinkGetDeviceList() ([]*DevlinkDevice, error)
// DevLinkGetDeviceList provides a pointer to devlink devices and nil error, // otherwise returns an error code. func (h *Handle) DevLinkGetDeviceList() ([]*DevlinkDevice, error)
{ f, err := h.GenlFamilyGet(nl.GENL_DEVLINK_NAME) if err != nil { return nil, err } msg := &nl.Genlmsg{ Command: nl.DEVLINK_CMD_GET, Version: nl.GENL_DEVLINK_VERSION, } req := h.newNetlinkRequest(int(f.ID), unix.NLM_F_REQUEST|unix.NLM_F_ACK|unix.NLM_F_DUMP) req.AddData(msg) msgs, err := req.Execute(unix.NETLINK_GENERIC, 0) if err != nil { return nil, err } devices, err := parseDevLinkDeviceList(msgs) if err != nil { return nil, err } for _, d := range devices { h.getEswitchAttrs(f, d) } return devices, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
devlink_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/devlink_linux.go#L222-L237
go
train
// DevlinkGetDeviceByName provides a pointer to devlink device and nil error, // otherwise returns an error code.
func (h *Handle) DevLinkGetDeviceByName(Bus string, Device string) (*DevlinkDevice, error)
// DevlinkGetDeviceByName provides a pointer to devlink device and nil error, // otherwise returns an error code. func (h *Handle) DevLinkGetDeviceByName(Bus string, Device string) (*DevlinkDevice, error)
{ f, req, err := h.createCmdReq(nl.DEVLINK_CMD_GET, Bus, Device) if err != nil { return nil, err } respmsg, err := req.Execute(unix.NETLINK_GENERIC, 0) if err != nil { return nil, err } dev, err := parseDevlinkDevice(respmsg) if err == nil { h.getEswitchAttrs(f, dev) } return dev, err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
devlink_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/devlink_linux.go#L241-L243
go
train
// DevlinkGetDeviceByName provides a pointer to devlink device and nil error, // otherwise returns an error code.
func DevLinkGetDeviceByName(Bus string, Device string) (*DevlinkDevice, error)
// DevlinkGetDeviceByName provides a pointer to devlink device and nil error, // otherwise returns an error code. func DevLinkGetDeviceByName(Bus string, Device string) (*DevlinkDevice, error)
{ return pkgHandle.DevLinkGetDeviceByName(Bus, Device) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
devlink_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/devlink_linux.go#L249-L264
go
train
// DevLinkSetEswitchMode sets eswitch mode if able to set successfully or // returns an error code. // Equivalent to: `devlink dev eswitch set $dev mode switchdev` // Equivalent to: `devlink dev eswitch set $dev mode legacy`
func (h *Handle) DevLinkSetEswitchMode(Dev *DevlinkDevice, NewMode string) error
// DevLinkSetEswitchMode sets eswitch mode if able to set successfully or // returns an error code. // Equivalent to: `devlink dev eswitch set $dev mode switchdev` // Equivalent to: `devlink dev eswitch set $dev mode legacy` func (h *Handle) DevLinkSetEswitchMode(Dev *DevlinkDevice, NewMode string) error
{ mode, err := eswitchStringToMode(NewMode) if err != nil { return err } _, req, err := h.createCmdReq(nl.DEVLINK_CMD_ESWITCH_SET, Dev.BusName, Dev.DeviceName) if err != nil { return err } req.AddData(nl.NewRtAttr(nl.DEVLINK_ATTR_ESWITCH_MODE, nl.Uint16Attr(mode))) _, err = req.Execute(unix.NETLINK_GENERIC, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
devlink_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/devlink_linux.go#L270-L272
go
train
// DevLinkSetEswitchMode sets eswitch mode if able to set successfully or // returns an error code. // Equivalent to: `devlink dev eswitch set $dev mode switchdev` // Equivalent to: `devlink dev eswitch set $dev mode legacy`
func DevLinkSetEswitchMode(Dev *DevlinkDevice, NewMode string) error
// DevLinkSetEswitchMode sets eswitch mode if able to set successfully or // returns an error code. // Equivalent to: `devlink dev eswitch set $dev mode switchdev` // Equivalent to: `devlink dev eswitch set $dev mode legacy` func DevLinkSetEswitchMode(Dev *DevlinkDevice, NewMode string) error
{ return pkgHandle.DevLinkSetEswitchMode(Dev, NewMode) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
rdma_link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/rdma_link_linux.go#L112-L118
go
train
// RdmaLinkByName finds a link by name and returns a pointer to the object if // found and nil error, otherwise returns error code.
func (h *Handle) RdmaLinkByName(name string) (*RdmaLink, error)
// RdmaLinkByName finds a link by name and returns a pointer to the object if // found and nil error, otherwise returns error code. func (h *Handle) RdmaLinkByName(name string) (*RdmaLink, error)
{ proto := getProtoField(nl.RDMA_NL_NLDEV, nl.RDMA_NLDEV_CMD_GET) req := h.newNetlinkRequest(proto, unix.NLM_F_ACK|unix.NLM_F_DUMP) return execRdmaGetLink(req, name) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
rdma_link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/rdma_link_linux.go#L123-L125
go
train
// RdmaLinkSetName sets the name of the rdma link device. Return nil on success // or error otherwise. // Equivalent to: `rdma dev set $old_devname name $name`
func RdmaLinkSetName(link *RdmaLink, name string) error
// RdmaLinkSetName sets the name of the rdma link device. Return nil on success // or error otherwise. // Equivalent to: `rdma dev set $old_devname name $name` func RdmaLinkSetName(link *RdmaLink, name string) error
{ return pkgHandle.RdmaLinkSetName(link, name) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
rdma_link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/rdma_link_linux.go#L130-L145
go
train
// RdmaLinkSetName sets the name of the rdma link device. Return nil on success // or error otherwise. // Equivalent to: `rdma dev set $old_devname name $name`
func (h *Handle) RdmaLinkSetName(link *RdmaLink, name string) error
// RdmaLinkSetName sets the name of the rdma link device. Return nil on success // or error otherwise. // Equivalent to: `rdma dev set $old_devname name $name` func (h *Handle) RdmaLinkSetName(link *RdmaLink, name string) error
{ proto := getProtoField(nl.RDMA_NL_NLDEV, nl.RDMA_NLDEV_CMD_SET) req := h.newNetlinkRequest(proto, unix.NLM_F_ACK) b := make([]byte, 4) native.PutUint32(b, uint32(link.Attrs.Index)) data := nl.NewRtAttr(nl.RDMA_NLDEV_ATTR_DEV_INDEX, b) req.AddData(data) b = make([]byte, len(name)+1) copy(b, name) data = nl.NewRtAttr(nl.RDMA_NLDEV_ATTR_DEV_NAME, b) req.AddData(data) return execRdmaSetLink(req) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
netlink.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netlink.go#L25-L32
go
train
// ParseIPNet parses a string in ip/net format and returns a net.IPNet. // This is valuable because addresses in netlink are often IPNets and // ParseCIDR returns an IPNet with the IP part set to the base IP of the // range.
func ParseIPNet(s string) (*net.IPNet, error)
// ParseIPNet parses a string in ip/net format and returns a net.IPNet. // This is valuable because addresses in netlink are often IPNets and // ParseCIDR returns an IPNet with the IP part set to the base IP of the // range. func ParseIPNet(s string) (*net.IPNet, error)
{ ip, ipNet, err := net.ParseCIDR(s) if err != nil { return nil, err } ipNet.IP = ip return ipNet, nil }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
netlink.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netlink.go#L35-L40
go
train
// NewIPNet generates an IPNet from an ip address using a netmask of 32 or 128.
func NewIPNet(ip net.IP) *net.IPNet
// NewIPNet generates an IPNet from an ip address using a netmask of 32 or 128. func NewIPNet(ip net.IP) *net.IPNet
{ if ip.To4() != nil { return &net.IPNet{IP: ip, Mask: net.CIDRMask(32, 32)} } return &net.IPNet{IP: ip, Mask: net.CIDRMask(128, 128)} }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L125-L139
go
train
// LinkSetAllmulticastOn enables the reception of all hardware multicast packets for the link device. // Equivalent to: `ip link set $link allmulticast on`
func (h *Handle) LinkSetAllmulticastOn(link Link) error
// LinkSetAllmulticastOn enables the reception of all hardware multicast packets for the link device. // Equivalent to: `ip link set $link allmulticast on` func (h *Handle) LinkSetAllmulticastOn(link Link) error
{ base := link.Attrs() h.ensureIndex(base) req := h.newNetlinkRequest(unix.RTM_NEWLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Change = unix.IFF_ALLMULTI msg.Flags = unix.IFF_ALLMULTI msg.Index = int32(base.Index) req.AddData(msg) _, err := req.Execute(unix.NETLINK_ROUTE, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L311-L313
go
train
// LinkSetMTU sets the mtu of the link device. // Equivalent to: `ip link set $link mtu $mtu`
func LinkSetMTU(link Link, mtu int) error
// LinkSetMTU sets the mtu of the link device. // Equivalent to: `ip link set $link mtu $mtu` func LinkSetMTU(link Link, mtu int) error
{ return pkgHandle.LinkSetMTU(link, mtu) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L338-L340
go
train
// LinkSetName sets the name of the link device. // Equivalent to: `ip link set $link name $name`
func LinkSetName(link Link, name string) error
// LinkSetName sets the name of the link device. // Equivalent to: `ip link set $link name $name` func LinkSetName(link Link, name string) error
{ return pkgHandle.LinkSetName(link, name) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L344-L358
go
train
// LinkSetName sets the name of the link device. // Equivalent to: `ip link set $link name $name`
func (h *Handle) LinkSetName(link Link, name string) error
// LinkSetName sets the name of the link device. // Equivalent to: `ip link set $link name $name` func (h *Handle) LinkSetName(link Link, name string) error
{ base := link.Attrs() h.ensureIndex(base) req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(base.Index) req.AddData(msg) data := nl.NewRtAttr(unix.IFLA_IFNAME, []byte(name)) req.AddData(data) _, err := req.Execute(unix.NETLINK_ROUTE, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L362-L364
go
train
// LinkSetAlias sets the alias of the link device. // Equivalent to: `ip link set dev $link alias $name`
func LinkSetAlias(link Link, name string) error
// LinkSetAlias sets the alias of the link device. // Equivalent to: `ip link set dev $link alias $name` func LinkSetAlias(link Link, name string) error
{ return pkgHandle.LinkSetAlias(link, name) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L386-L388
go
train
// LinkSetHardwareAddr sets the hardware address of the link device. // Equivalent to: `ip link set $link address $hwaddr`
func LinkSetHardwareAddr(link Link, hwaddr net.HardwareAddr) error
// LinkSetHardwareAddr sets the hardware address of the link device. // Equivalent to: `ip link set $link address $hwaddr` func LinkSetHardwareAddr(link Link, hwaddr net.HardwareAddr) error
{ return pkgHandle.LinkSetHardwareAddr(link, hwaddr) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L392-L406
go
train
// LinkSetHardwareAddr sets the hardware address of the link device. // Equivalent to: `ip link set $link address $hwaddr`
func (h *Handle) LinkSetHardwareAddr(link Link, hwaddr net.HardwareAddr) error
// LinkSetHardwareAddr sets the hardware address of the link device. // Equivalent to: `ip link set $link address $hwaddr` func (h *Handle) LinkSetHardwareAddr(link Link, hwaddr net.HardwareAddr) error
{ base := link.Attrs() h.ensureIndex(base) req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(base.Index) req.AddData(msg) data := nl.NewRtAttr(unix.IFLA_ADDRESS, []byte(hwaddr)) req.AddData(data) _, err := req.Execute(unix.NETLINK_ROUTE, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L410-L412
go
train
// LinkSetVfHardwareAddr sets the hardware address of a vf for the link. // Equivalent to: `ip link set $link vf $vf mac $hwaddr`
func LinkSetVfHardwareAddr(link Link, vf int, hwaddr net.HardwareAddr) error
// LinkSetVfHardwareAddr sets the hardware address of a vf for the link. // Equivalent to: `ip link set $link vf $vf mac $hwaddr` func LinkSetVfHardwareAddr(link Link, vf int, hwaddr net.HardwareAddr) error
{ return pkgHandle.LinkSetVfHardwareAddr(link, vf, hwaddr) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L416-L436
go
train
// LinkSetVfHardwareAddr sets the hardware address of a vf for the link. // Equivalent to: `ip link set $link vf $vf mac $hwaddr`
func (h *Handle) LinkSetVfHardwareAddr(link Link, vf int, hwaddr net.HardwareAddr) error
// LinkSetVfHardwareAddr sets the hardware address of a vf for the link. // Equivalent to: `ip link set $link vf $vf mac $hwaddr` func (h *Handle) LinkSetVfHardwareAddr(link Link, vf int, hwaddr net.HardwareAddr) error
{ base := link.Attrs() h.ensureIndex(base) req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(base.Index) req.AddData(msg) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil) vfmsg := nl.VfMac{ Vf: uint32(vf), } copy(vfmsg.Mac[:], []byte(hwaddr)) info.AddRtAttr(nl.IFLA_VF_MAC, vfmsg.Serialize()) req.AddData(data) _, err := req.Execute(unix.NETLINK_ROUTE, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L440-L442
go
train
// LinkSetVfVlan sets the vlan of a vf for the link. // Equivalent to: `ip link set $link vf $vf vlan $vlan`
func LinkSetVfVlan(link Link, vf, vlan int) error
// LinkSetVfVlan sets the vlan of a vf for the link. // Equivalent to: `ip link set $link vf $vf vlan $vlan` func LinkSetVfVlan(link Link, vf, vlan int) error
{ return pkgHandle.LinkSetVfVlan(link, vf, vlan) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L446-L466
go
train
// LinkSetVfVlan sets the vlan of a vf for the link. // Equivalent to: `ip link set $link vf $vf vlan $vlan`
func (h *Handle) LinkSetVfVlan(link Link, vf, vlan int) error
// LinkSetVfVlan sets the vlan of a vf for the link. // Equivalent to: `ip link set $link vf $vf vlan $vlan` func (h *Handle) LinkSetVfVlan(link Link, vf, vlan int) error
{ base := link.Attrs() h.ensureIndex(base) req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(base.Index) req.AddData(msg) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil) vfmsg := nl.VfVlan{ Vf: uint32(vf), Vlan: uint32(vlan), } info.AddRtAttr(nl.IFLA_VF_VLAN, vfmsg.Serialize()) req.AddData(data) _, err := req.Execute(unix.NETLINK_ROUTE, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L470-L472
go
train
// LinkSetVfTxRate sets the tx rate of a vf for the link. // Equivalent to: `ip link set $link vf $vf rate $rate`
func LinkSetVfTxRate(link Link, vf, rate int) error
// LinkSetVfTxRate sets the tx rate of a vf for the link. // Equivalent to: `ip link set $link vf $vf rate $rate` func LinkSetVfTxRate(link Link, vf, rate int) error
{ return pkgHandle.LinkSetVfTxRate(link, vf, rate) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L476-L496
go
train
// LinkSetVfTxRate sets the tx rate of a vf for the link. // Equivalent to: `ip link set $link vf $vf rate $rate`
func (h *Handle) LinkSetVfTxRate(link Link, vf, rate int) error
// LinkSetVfTxRate sets the tx rate of a vf for the link. // Equivalent to: `ip link set $link vf $vf rate $rate` func (h *Handle) LinkSetVfTxRate(link Link, vf, rate int) error
{ base := link.Attrs() h.ensureIndex(base) req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(base.Index) req.AddData(msg) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil) vfmsg := nl.VfTxRate{ Vf: uint32(vf), Rate: uint32(rate), } info.AddRtAttr(nl.IFLA_VF_TX_RATE, vfmsg.Serialize()) req.AddData(data) _, err := req.Execute(unix.NETLINK_ROUTE, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L500-L502
go
train
// LinkSetVfSpoofchk enables/disables spoof check on a vf for the link. // Equivalent to: `ip link set $link vf $vf spoofchk $check`
func LinkSetVfSpoofchk(link Link, vf int, check bool) error
// LinkSetVfSpoofchk enables/disables spoof check on a vf for the link. // Equivalent to: `ip link set $link vf $vf spoofchk $check` func LinkSetVfSpoofchk(link Link, vf int, check bool) error
{ return pkgHandle.LinkSetVfSpoofchk(link, vf, check) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L506-L530
go
train
// LinkSetVfSpoofchk enables/disables spoof check on a vf for the link. // Equivalent to: `ip link set $link vf $vf spoofchk $check`
func (h *Handle) LinkSetVfSpoofchk(link Link, vf int, check bool) error
// LinkSetVfSpoofchk enables/disables spoof check on a vf for the link. // Equivalent to: `ip link set $link vf $vf spoofchk $check` func (h *Handle) LinkSetVfSpoofchk(link Link, vf int, check bool) error
{ var setting uint32 base := link.Attrs() h.ensureIndex(base) req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(base.Index) req.AddData(msg) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil) if check { setting = 1 } vfmsg := nl.VfSpoofchk{ Vf: uint32(vf), Setting: setting, } info.AddRtAttr(nl.IFLA_VF_SPOOFCHK, vfmsg.Serialize()) req.AddData(data) _, err := req.Execute(unix.NETLINK_ROUTE, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L534-L536
go
train
// LinkSetVfTrust enables/disables trust state on a vf for the link. // Equivalent to: `ip link set $link vf $vf trust $state`
func LinkSetVfTrust(link Link, vf int, state bool) error
// LinkSetVfTrust enables/disables trust state on a vf for the link. // Equivalent to: `ip link set $link vf $vf trust $state` func LinkSetVfTrust(link Link, vf int, state bool) error
{ return pkgHandle.LinkSetVfTrust(link, vf, state) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L568-L570
go
train
// LinkSetVfNodeGUID sets the node GUID of a vf for the link. // Equivalent to: `ip link set dev $link vf $vf node_guid $nodeguid`
func LinkSetVfNodeGUID(link Link, vf int, nodeguid net.HardwareAddr) error
// LinkSetVfNodeGUID sets the node GUID of a vf for the link. // Equivalent to: `ip link set dev $link vf $vf node_guid $nodeguid` func LinkSetVfNodeGUID(link Link, vf int, nodeguid net.HardwareAddr) error
{ return pkgHandle.LinkSetVfGUID(link, vf, nodeguid, nl.IFLA_VF_IB_NODE_GUID) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L574-L576
go
train
// LinkSetVfPortGUID sets the port GUID of a vf for the link. // Equivalent to: `ip link set dev $link vf $vf port_guid $portguid`
func LinkSetVfPortGUID(link Link, vf int, portguid net.HardwareAddr) error
// LinkSetVfPortGUID sets the port GUID of a vf for the link. // Equivalent to: `ip link set dev $link vf $vf port_guid $portguid` func LinkSetVfPortGUID(link Link, vf int, portguid net.HardwareAddr) error
{ return pkgHandle.LinkSetVfGUID(link, vf, portguid, nl.IFLA_VF_IB_PORT_GUID) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L579-L608
go
train
// LinkSetVfGUID sets the node or port GUID of a vf for the link.
func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidType int) error
// LinkSetVfGUID sets the node or port GUID of a vf for the link. func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidType int) error
{ var err error var guid uint64 buf := bytes.NewBuffer(vfGuid) err = binary.Read(buf, binary.LittleEndian, &guid) if err != nil { return err } base := link.Attrs() h.ensureIndex(base) req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(base.Index) req.AddData(msg) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil) vfmsg := nl.VfGUID{ Vf: uint32(vf), GUID: guid, } info.AddRtAttr(guidType, vfmsg.Serialize()) req.AddData(data) _, err = req.Execute(unix.NETLINK_ROUTE, 0) return err }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L612-L614
go
train
// LinkSetMaster sets the master of the link device. // Equivalent to: `ip link set $link master $master`
func LinkSetMaster(link Link, master *Bridge) error
// LinkSetMaster sets the master of the link device. // Equivalent to: `ip link set $link master $master` func LinkSetMaster(link Link, master *Bridge) error
{ return pkgHandle.LinkSetMaster(link, master) }
vishvananda/netlink
fd97bf4e47867b5e794234baa6b8a7746135ec10
link_linux.go
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L618-L629
go
train
// LinkSetMaster sets the master of the link device. // Equivalent to: `ip link set $link master $master`
func (h *Handle) LinkSetMaster(link Link, master *Bridge) error
// LinkSetMaster sets the master of the link device. // Equivalent to: `ip link set $link master $master` func (h *Handle) LinkSetMaster(link Link, master *Bridge) error
{ index := 0 if master != nil { masterBase := master.Attrs() h.ensureIndex(masterBase) index = masterBase.Index } if index <= 0 { return fmt.Errorf("Device does not exist") } return h.LinkSetMasterByIndex(link, index) }