Skip to content

Netlink Go package for listening to interface events and getting extended flags such as IFF_RUNNING.

License

Notifications You must be signed in to change notification settings

ake-persson/netlink

Repository files navigation

GoDoc

netlink

import "github.com/mickep76/netlink"

interfaces.go netlink.go parse_newlink.go

const (
    // NetlinkRoute return socket descriptor.
    NetlinkRoute = 0

    // RtmGrpLink Rtnetlink multicast group.
    RtmGrpLink = 0x1
)
func Interfaces() ([]Interface, error)

Interfaces connect using rtnetlink and retrieve all network interfaces.

type Conn struct {
    Family     int
    Groups     uint32
    FileDescr  int
    SocketAddr *unix.SockaddrNetlink
    Pid        uint32
}

Conn provides an interface for connecting to netlink socket.

func Dial(family int, groups uint32) (*Conn, error)

Dial netlink socket.

func (*Conn) Bind

func (c *Conn) Bind() error

Bind to netlink socket.

func (*Conn) Close

func (c *Conn) Close() error

Close netlink socket.

func (*Conn) Receive

func (c *Conn) Receive() ([]syscall.NetlinkMessage, error)

Receive messages from netlink socket.

type Flags uint

Flags type for network interface state.

const (
    // FlagUp interface is up (administratively).
    FlagUp Flags = 1 << iota

    // FlagBroadcast broadcast address valid.
    FlagBroadcast

    // FlagDebug turn on debugging.
    FlagDebug

    // FlagLoopback is a loopback net.
    FlagLoopback

    // FlagPointToPoint interface is has p-p link.
    FlagPointToPoint

    // FlagNoTrailers avoid use of trailers.
    FlagNoTrailers

    // FlagRunning interface RFC2863 OPER_UP.
    FlagRunning

    // FlagNoArp no ARP protocol.
    FlagNoArp

    // FlagPromisc receive all packets.
    FlagPromisc

    // FlagAllMulti receive all multicast packets.
    FlagAllMulti

    // FlagMaster master of a load balancer.
    FlagMaster

    // FlagSlave slave of a load balancer.
    FlagSlave

    // FlagMulticast supports multicast.
    FlagMulticast

    // FlagPortSel can set media type.
    FlagPortSel

    // FlagAutoMedia auto media select active.
    FlagAutoMedia

    // FlagDynamic dialup device with changing addresses.
    FlagDynamic

    // FlagLowerUp driver signals L1 up.
    FlagLowerUp

    // FlagDormant driver signals dormant.
    FlagDormant

    // FlagEcho echo sent packets.
    FlagEcho
)
func (f Flags) MarshalJSON() ([]byte, error)

MarshalJSON marshal flags into JSON.

func (Flags) Slice

func (f Flags) Slice() []string

Slice return a list of all flags.

func (Flags) String

func (f Flags) String() string

String return a string of all flags.

type HwAddr []byte

HwAddr hardware address type.

func (HwAddr) MarshalJSON

func (a HwAddr) MarshalJSON() ([]byte, error)

MarshalJSON marshal hardware address into JSON.

func (HwAddr) String

func (a HwAddr) String() string
type Interface struct {
    Index        int            `json:"index"`
    MTU          int            `json:"mtu"`
    Name         string         `json:"name"`
    HwAddr       HwAddr         `json:"hwaddr,omitempty"`
    Flags        Flags          `json:"flags"`
    NetInterface *net.Interface `json:"-"`
}

Interface provides information about a network interface.

func ParseNewLink(ifim *syscall.IfInfomsg, attrs []syscall.NetlinkRouteAttr) *Interface

ParseNewLink parse interface info message.

Credits

  • Parse messages based on Go package net.
  • Socket connection based on Go package mdlayher/netlink.

About

Netlink Go package for listening to interface events and getting extended flags such as IFF_RUNNING.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published