Code Monkey home page Code Monkey logo

netlink's Introduction

netlink - netlink library for go

Build Status GoDoc

The netlink package provides a simple netlink library for go. Netlink is the interface a user-space program in linux uses to communicate with the kernel. It can be used to add and remove interfaces, set ip addresses and routes, and configure ipsec. Netlink communication requires elevated privileges, so in most cases this code needs to be run as root. Since low-level netlink messages are inscrutable at best, the library attempts to provide an api that is loosely modeled on the CLI provided by iproute2. Actions like ip link add will be accomplished via a similarly named function like AddLink(). This library began its life as a fork of the netlink functionality in docker/libcontainer but was heavily rewritten to improve testability, performance, and to add new functionality like ipsec xfrm handling.

Local Build and Test

You can use go get command:

go get github.com/vishvananda/netlink

Testing dependencies:

go get github.com/vishvananda/netns

Testing (requires root):

sudo -E go test github.com/vishvananda/netlink

Examples

Add a new bridge and add eth1 into it:

package main

import (
    "fmt"
    "github.com/vishvananda/netlink"
)

func main() {
    la := netlink.NewLinkAttrs()
    la.Name = "foo"
    mybridge := &netlink.Bridge{LinkAttrs: la}
    err := netlink.LinkAdd(mybridge)
    if err != nil  {
        fmt.Printf("could not add %s: %v\n", la.Name, err)
    }
    eth1, _ := netlink.LinkByName("eth1")
    netlink.LinkSetMaster(eth1, mybridge)
}

Note NewLinkAttrs constructor, it sets default values in structure. For now it sets only TxQLen to -1, so kernel will set default by itself. If you're using simple initialization(LinkAttrs{Name: "foo"}) TxQLen will be set to 0 unless you specify it like LinkAttrs{Name: "foo", TxQLen: 1000}.

Add a new ip address to loopback:

package main

import (
    "github.com/vishvananda/netlink"
)

func main() {
    lo, _ := netlink.LinkByName("lo")
    addr, _ := netlink.ParseAddr("169.254.169.254/32")
    netlink.AddrAdd(lo, addr)
}

Future Work

Many pieces of netlink are not yet fully supported in the high-level interface. Aspects of virtually all of the high-level objects don't exist. Many of the underlying primitives are there, so its a matter of putting the right fields into the high-level objects and making sure that they are serialized and deserialized correctly in the Add and List methods.

There are also a few pieces of low level netlink functionality that still need to be implemented. Routing rules are not in place and some of the more advanced link types. Hopefully there is decent structure and testing in place to make these fairly straightforward to add.

netlink's People

Contributors

aboch avatar adrianchiris avatar avagin avatar bboreham avatar borkmann avatar brb avatar chantra avatar cjmakes avatar corny avatar ctrlzvi avatar dave-tucker avatar e0ne avatar ebiken avatar ejj avatar hiepon avatar hmahmood avatar kishiguro avatar lebauce avatar lk4d4 avatar marek-polewski avatar mcastelino avatar paravmellanox avatar rgo3 avatar safchain avatar sargun avatar tfukushima avatar tklauser avatar udhos avatar vincentbernat avatar vishvananda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

netlink's Issues

default state for network links

FYI. I use netlink to create bridge, veth pair. I found the initial state is up, so I don't need to call LinkSetUp function, is this right?

no such device from LinkSetNsPid for veth

I create veth interface for my custom network configuration and some time i see no such device errors when i'm trying to call netlink.LinkSetNsPid on the newly created interface.

The interesting thing that i was able to obtain link handle via LinkByName or via LinkList before i called LinkSetNsPid, so device was created successfully. I also see devices created with ip link

I started debugging and added LinkList just after the error happened + another one with 1 second delay. What i see consistently (if the issue occurred) is pretty weird: the first output usually contains only few records with incorrect device index values, while the second one has all the records i has configured on the host with correct indexes.

1st output (just after failure), LinkList results has size 3:

time="2016-12-19T10:43:40Z" level=warning msg="=== debug interfaces, 1st attempt ==="
time="2016-12-19T10:43:40Z" level=debug msg="=== current interfaces list (count 3) ==="
time="2016-12-19T10:43:40Z" level=debug msg="interface record -> name: lo idx: 1"
time="2016-12-19T10:43:40Z" level=debug msg="interface record -> name: vethbada13B idx: 2"
time="2016-12-19T10:43:40Z" level=debug msg="interface record -> name: vethbada13A idx: 3"
time="2016-12-19T10:43:40Z" level=debug msg="=== end current interface list ==="

2nd attempt output (after 1 second), LinkList result has size 23 (expected)

time="2016-12-19T10:43:41Z" level=warning msg="=== debug interfaces, 2nd attempt ==="
time="2016-12-19T10:43:41Z" level=debug msg="=== current interfaces list (count 23) ==="
time="2016-12-19T10:43:41Z" level=debug msg="interface record -> name: lo idx: 1"
time="2016-12-19T10:43:41Z" level=debug msg="interface record -> name: eth0 idx: 2"
time="2016-12-19T10:43:41Z" level=debug msg="interface record -> name: docker0 idx: 3"
time="2016-12-19T10:43:41Z" level=debug msg="interface record -> name: eth1 idx: 4"
time="2016-12-19T10:43:41Z" level=debug msg="interface record -> name: vetha434e0B idx: 1036"
time="2016-12-19T10:43:41Z" level=debug msg="interface record -> name: vetha434e0A idx: 1037"

We start a lot of containers and this issue happens only in about 0.5-1% launches (100 crashes out of 20000 tasks last night). We run on AWS and our instances are recycled once in a few days, but even with that, the issue tends to happen on the same subset of hosts where it happened once. (3-5 hosts out of 200)

@vishvananda i'm not sure if it's go netlink bug or some kernel issue. If you have any recommendations what to look at next, it would be super helpful. I can add more output to the netlink as well.

Our configuration is

Linux mainvpc-r3.8xlarge-i-00e3fe8d965d0c577 3.19.0-26-generic #28~14.04.1-Ubuntu SMP Wed Aug 12 14:09:17 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Master does not build on GOOS=darwin

$ go get github.com/vishvananda/netlink
# github.com/vishvananda/netlink
../../go/src/github.com/vishvananda/netlink/filter.go:225: undefined: nl.TcPolice

PS. This issue was found with the use of this library in coreos/fleet.
See coreos/fleet#1604

Include support for reading the IFF_RUNNING flag

I would like to monitor the state of an ethernet interface and have tried using "LinkSubscribe". I get events, but unfortunately the events that I get always have the "UP" flag set even when the ethernet cable is removed. In contrast, "ip monitor link" reports "DOWN" when the cable is removed.

It sounds like this issue:
http://stackoverflow.com/questions/11679514/what-is-the-difference-between-iff-up-and-iff-running?answertab=votes#tab-top

Changing "linkFlags()" to use syscall.IFF_RUNNING instead of syscall.IFF_UP works for me but seems to change the meaning of the flags, so I'm not sure what your proposed solution is.

time.Duration instead of uint64 for some fields

Have you considered using time.Duration instead of uint64's for some of your time fields?

It'll make your interfaces a little more go-idiomatic and give you a standard way of transporting time types agnostic to units.

This is mostly a suggestion. If you have a compelling reason not to use time.Duration I'm curious to know what it is.

Some things that might be simplified using time.Duration:

https://github.com/vishvananda/netlink/blob/master/nl/xfrm_linux.go#L219-L220
https://github.com/vishvananda/netlink/blob/master/qdisc_linux.go#L234

mode on macvtap interfaces not set correctly

The mode on macvtap interfaces is not set correctly. The mode is being set only for macvlan interfaces. It should be set for both macvlan and macvtap.

Will submit a PR to fix this.

    } else if macv, ok := link.(*Macvlan); ok {
            if macv.Mode != MACVLAN_MODE_DEFAULT {
                    data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil)
                    nl.NewRtAttrChild(data, nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[macv.Mode]))
            }
    } else if macv, ok := link.(*Macvtap); ok {
            if macv.Mode != MACVLAN_MODE_DEFAULT {
                    data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil)
                    nl.NewRtAttrChild(data, nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[macv.Mode]))
            }
    } 

panic

package main
import (
 "log"
 "github.com/vishvananda/netlink"
)
func main() {
 link, err := netlink.LinkByName("eth0")
 if err != nil {
  panic(err)
 }
 routes, err := netlink.RouteList(link, netlink.FAMILY_V4)
 if err != nil {
  panic(err)
 }
 log.Printf("r %+v\n", routes)
}

2015/01/15 23:15:05 r %!v(PANIC=runtime error: invalid memory address or nil pointer dereference)

Tests fail to build on linux/s390x

In golang/go#18628 it was reported that the tests for this package fail to build on linux/s390x because the syscall.IfInfomsg.X__ifi_pad field isn't exported.

I've sent a CL to (maybe) get the field exported for Go 1.8 but would it be possible to remove the dependence on the value of the X__ifi_pad field from the tests in nl/nl_linux_test.go? Failing that, maybe it would be reasonable to skip building this file on s390x for now (i.e. add // +build !s390x to the top of the file)?

Also, out of interest do you know if the value of the X__ifi_pad field matters in any way (if it does it would help me make the case for getting it exported in the syscall library)?

Thanks.

cc @sharkcz

LinkSetMaster does not fail if bridge does not exist

I'm calling LinkSetMaster with a bridge that does not exist on the system like this err = netlink.LinkSetMaster(link, &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: bridgeName}}). The call returns success (nil), but it should return an error .

Using ip on the command line returns an error as expected:

ip link set haa master aa
Error: argument "aa" is wrong: Device does not exist

GBP field on netlink.Vxlan{}, if set to true, throws an error "numerical result out of range"

We have observed this in a live environment when experimenting with adding GBP to flannel. And by adding this to the netlink.Vxlan{} in unit tests:

diff --git a/link_test.go b/link_test.go
index ca11bb2..b654e4a 100644
--- a/link_test.go
+++ b/link_test.go
@@ -588,6 +588,7 @@ func TestLinkAddDelVxlan(t *testing.T) {
        Learning:     true,
        L2miss:       true,
        L3miss:       true,
+       GBP: true,
    }

    testLinkAddDel(t, &vxlan)

We see in the test results:

--- FAIL: TestLinkAddDelVxlan (0.45s)
    link_test.go:27: numerical result out of range

The flannel was running on kernel version 4.4.0
The unit tests were on kernel version 4.4.13

htb class does not correctly set buffer/cbuffer when rate == math.MaxUint64

As I was using the library and set a rate of math.MaxUint64, I noticed that buffer/cbuffer were set to 0.

Basically setting HtbClassAttrs.Rate to something greater than math.MaxUint32 * 8 will set incorrect values.
This is most likely happening due to casting and overflowing a type somewhere. I will look into it.

msg.Change value

0207b6b changed behavior a little.
From man 7 rtnetlink:

ifi_change is reserved for future use and should be always set to 0xFFFFFFFF.

Also when set to 0xFFFFFFFF any netlink call sets interface up(have no idea why). So, I'm not sure what sense make set msg.Change to anything. It works with any value, but with 0xFFFFFFFF it also sets interface up :)
ping @vishvananda @marek-polewski

Arm nil reference exception with "protocol not supported"

This is referencing this docker issue: moby/moby#24018

On ARMv7 on an Odroid U3 with kernel version 4.6.3

could not create netlink handle on initial namespace: protocol not supported

This results in a nil reference exception:

May 21 22:36:04 u3 systemd[1]: Starting Docker Application Container Engine...
May 21 22:36:04 u3 dockerd[5308]: time="2016-05-21T22:36:04.625731116Z" level=info msg="New containerd process, pid: 5323"
May 21 22:36:05 u3 dockerd[5308]: time="2016-05-21T22:36:05.711054324Z" level=info msg="Graph migration to content-addressability took 0.00 seconds"
May 21 22:36:05 u3 dockerd[5308]: time="2016-05-21T22:36:05.716723949Z" level=warning msg="mountpoint for pids not found"
May 21 22:36:05 u3 dockerd[5308]: time="2016-05-21T22:36:05.720063074Z" level=info msg="Loading containers: start."
May 21 22:36:05 u3 dockerd[5308]: time="2016-05-21T22:36:05.913945908Z" level=info msg="Firewalld running: false"
May 21 22:36:06 u3 dockerd[5308]: time="2016-05-21T22:36:06.081978699Z" level=error msg="could not create netlink handle on initial namespace: protocol not supported"
May 21 22:36:06 u3 dockerd[5308]: time="2016-05-21T22:36:06.087732533Z" level=error msg="could not create netlink handle on initial namespace: protocol not supported"
May 21 22:36:06 u3 dockerd[5308]: panic: runtime error: invalid memory address or nil pointer dereference
May 21 22:36:06 u3 dockerd[5308]: [signal 0xb code=0x1 addr=0xc pc=0x989ff4]
May 21 22:36:06 u3 dockerd[5308]: goroutine 1 [running]:
May 21 22:36:06 u3 dockerd[5308]: panic(0x11e9158, 0x11e1e030)
May 21 22:36:06 u3 dockerd[5308]:         /skiff/workspaces/u/output/host/usr/lib/go/src/runtime/panic.go:481 +0x330
May 21 22:36:06 u3 dockerd[5308]: github.com/vishvananda/netlink.(*Handle).LinkByName(0x0, 0x1356aa8, 0x7, 0x0, 0x0, 0x0, 0x0)
May 21 22:36:06 u3 dockerd[5308]:         /skiff/workspaces/u/output/build/docker-engine-v1.12.0-rc2/vendor/src/github.com/vishvananda/netlink/link_linux.go:759 +0x$8
May 21 22:36:06 u3 dockerd[5308]: github.com/docker/libnetwork/netutils.ElectInterfaceAddresses(0x1356aa8, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
May 21 22:36:06 u3 dockerd[5308]:         /skiff/workspaces/u/output/build/docker-engine-v1.12.0-rc2/vendor/src/github.com/docker/libnetwork/netutils/utils_linux.go$78 +0xac
May 21 22:36:06 u3 dockerd[5308]: github.com/docker/docker/daemon.initBridgeDriver(0xb4dcbcf8, 0x11e85680, 0x120fc700, 0x0, 0x0)
May 21 22:36:06 u3 dockerd[5308]:         /skiff/workspaces/u/output/build/docker-engine-v1.12.0-rc2/vendor/src/github.com/docker/docker/daemon/daemon_unix.go:712 +$x4c0
May 21 22:36:06 u3 dockerd[5308]: github.com/docker/docker/daemon.(*Daemon).initNetworkController(0x11e01ee0, 0x120fc700, 0x121787e0, 0x0, 0x0, 0x0, 0x0)
May 21 22:36:06 u3 dockerd[5308]:         /skiff/workspaces/u/output/build/docker-engine-v1.12.0-rc2/vendor/src/github.com/docker/docker/daemon/daemon_unix.go:661 +$x5cc
May 21 22:36:06 u3 dockerd[5308]: github.com/docker/docker/daemon.(*Daemon).restore(0x11e01ee0, 0x0, 0x0)
May 21 22:36:06 u3 dockerd[5308]:         /skiff/workspaces/u/output/build/docker-engine-v1.12.0-rc2/vendor/src/github.com/docker/docker/daemon/daemon.go:223 +0xc98
May 21 22:36:06 u3 dockerd[5308]: github.com/docker/docker/daemon.NewDaemon(0x120fc700, 0xb5f32628, 0x12005620, 0xb5f32458, 0x12106310, 0x0, 0x0, 0x0)
May 21 22:36:06 u3 dockerd[5308]:         /skiff/workspaces/u/output/build/docker-engine-v1.12.0-rc2/vendor/src/github.com/docker/docker/daemon/daemon.go:596 +0x2aa$
May 21 22:36:06 u3 dockerd[5308]: main.(*DaemonCli).start(0x120f9de0, 0x0, 0x0)
May 21 22:36:06 u3 dockerd[5308]:         /skiff/workspaces/u/output/build/docker-engine-v1.12.0-rc2/cmd/dockerd/daemon.go:269 +0x165c
May 21 22:36:06 u3 dockerd[5308]: main.main()
May 21 22:36:06 u3 dockerd[5308]:         /skiff/workspaces/u/output/build/docker-engine-v1.12.0-rc2/cmd/dockerd/docker.go:68 +0x470

Specifically:

github.com/vishvananda/netlink.(*Handle).LinkByName

Any ideas if this is a bug with this library or Docker or something else?

Support netem qdisc

netem qdisc provides support for:

  • latency
  • packet loss
  • packet corruption
  • packet reordering
  • packet duplication

migrate to golang.org/x/sys

The Go doc for syscall says:

NOTE: This package is locked down. Code outside the standard Go repository should be migrated to use the corresponding package in the golang.org/x/sys repository. That is also where updates required by new systems or versions should be applied. See https://golang.org/s/go1.4-syscall for more information.

How do I create a new Message type

Hey,
I'm trying to figure how do I request a new request to the Netfilter..
I found out this protocol documentation:

http://git.netfilter.org/ipset/tree/lib/PROTOCOL

req:    msg:    IPSET_CMD_LIST|SAVE
        attr:   IPSET_ATTR_PROTOCOL
                IPSET_ATTR_SETNAME  (optional)

resp:   attr:   IPSET_ATTR_SETNAME
                IPSET_ATTR_TYPENAME
                IPSET_ATTR_REVISION
                IPSET_ATTR_FAMILY
                IPSET_ATTR_DATA
                    create-specific-data
                IPSET_ATTR_ADT
                    IPSET_ATTR_DATA
                        adt-specific-data
                    ...

And this is the message structure I created:

type NfGenMsgn struct {
    Nfgen_family uint8
    Version uint8
    Res_id uint16
}

But how do I create the "serialize" and "len" methods for this structure?
Would love to get some guidance, and of course to send a PR in the end.

Parsing other messages [attrs]

Hi, can someone point me how to parse other messages than route?
I'm trying to map another kind of message(nl general message with attributes), but it's really hard to understand if it's even possible to do that with this library.. (also there is not documentation)

rule priority defaults to table id value when used with table id higher than 255

I'm trying to set a rule which look like this:
sudo ip rule add to 200.200.200.200 lookup 500 priority 3000

produces the following ip rule output:
3000: from all to 200.200.200.200 lookup 500

If the same operation applied with netlink:

_, dstIpNet, _ := net.ParseCIDR("200.200.200.200/32")
_, srcIpNet, _ := net.ParseCIDR("0.0.0.0/0")

rule := netlink.NewRule()
rule.Src = dstIpNet
rule.Dst = srcIpNet
rule.Priority = 3000
rule.Table = 500
netlink.RuleAdd(rule)`

It produces the following ip rule output:
500: from 200.200.200.200 lookup 500

I'm not sure what is the official support status for table ids higher than 255 in the recent kernels? It works fine with CLI and It looks like IDs > 255 work fine in netlink if we don't specify the priority field.

I tested it on 3.13.0-76-generic #120-Ubuntu

Any ideas?

rtm_type is missing on purpose?

I can't find the rtm_type's or any other way to define those in routes/rules. Are they missing on purpose? Or is this a work in progress?

          rtm_type          Route type
          ───────────────────────────────────────────────────────────
          RTN_UNSPEC        unknown route
          RTN_UNICAST       a gateway or direct route
          RTN_LOCAL         a local interface route
          RTN_BROADCAST     a local broadcast route (sent as a
                            broadcast)
          RTN_ANYCAST       a local broadcast route (sent as a
                            unicast)
          RTN_MULTICAST     a multicast route
          RTN_BLACKHOLE     a packet dropping route
          RTN_UNREACHABLE   an unreachable destination
          RTN_PROHIBIT      a packet rejection route
          RTN_THROW         continue routing lookup in another table
          RTN_NAT           a network address translation rule
          RTN_XRESOLVE      refer to an external resolver (not
                            implemented)

http://man7.org/linux/man-pages/man7/rtnetlink.7.html

I tried the following to get a default route on table 127 which points to a blackhole: (ip route add blackhole default table 127)

    src := net.IPv4(0, 0, 0, 0)
     route := nl.Route{LinkIndex: link.Attrs().Index, Src: src, Type: syscall.RTN_BLACKHOLE, Table: 127}
     if err := nl.RouteAdd(&route); err != nil {
            panic(err)
     }

Table 127 is empty and no matter what I still receive a panic.

panic: invalid argument

Thank you for this netlink library.

Build failure for windows binaries

Just pulled the latest, and get this when I try to build a windows binary:

vendor/github.com/vishvananda/netlink/xfrm.go:12: undefined: syscall.IPPROTO_ROUTING
vendor/github.com/vishvananda/netlink/xfrm.go:13: undefined: syscall.IPPROTO_ESP
vendor/github.com/vishvananda/netlink/xfrm.go:14: undefined: syscall.IPPROTO_AH
vendor/github.com/vishvananda/netlink/xfrm.go:15: undefined: syscall.IPPROTO_DSTOPTS
vendor/github.com/vishvananda/netlink/xfrm.go:17: undefined: syscall.IPPROTO_RAW

No buildable go source files

I'm having some issues installing this library. Still learning bits and pieces of the operations here, so feel free to point out a silly mistake.

It looks like I'm having problems retrieving building both the netlink and netns libraries. Any thoughts are appreciated. Output below:

~GOPATH/src/github.com $  go get github.com/vishvananda/netlink
vishvananda/netlink/netlink.go:14:2: no buildable Go source files in /Users/mierdin/Code/GO/src/github.com/vishvananda/netlink/nl

 ~GOPATH/src/github.com $  cd vishvananda/netlink
 ~GOPATH/src/github.com/vishvananda/netlink $  go build                                       
netlink.go:14:2: no buildable Go source files in /Users/mierdin/Code/GO/src/github.com/vishvananda/netlink/nl

 ~GOPATH/src/github.com/vishvananda/netlink $  go get github.com/vishvananda/netns
# github.com/vishvananda/netns
../netns/netns_unspecified.go:13: undefined: Namespace
../netns/netns_unspecified.go:17: undefined: Namespace
../netns/netns_unspecified.go:21: undefined: Namespace
../netns/netns_unspecified.go:25: undefined: Namespace
../netns/netns_unspecified.go:29: undefined: Namespace
../netns/netns_unspecified.go:33: undefined: Namespace

 ~GOPATH/src/github.com/vishvananda/netlink $  sudo -E go test github.com/vishvananda/netlink
netlink.go:14:2: no buildable Go source files in /Users/mierdin/Code/GO/src/github.com/vishvananda/netlink/nl
../netlink/netlink.go:14:2: no buildable Go source files in /Users/mierdin/Code/GO/src/github.com/vishvananda/netlink/nl

VxLAN port is not respected

Hello, I observe the following, when I vary the vxlan.Port from 1 to 3:

vxlan := &netlink.Vxlan{
            LinkAttrs: foo,
            VxlanId: 42,
            VtepDevIndex: 2,
            Port: 1 to 3,
            Learning: true,
            Group: net.IPv4(10,2,3,4),
        }
ip -d link show vx1
65: vx1: <BROADCAST,MULTICAST> mtu 1450 qdisc noop state DOWN mode DEFAULT group default 
    link/ether d2:7e:e8:0d:7e:06 brd ff:ff:ff:ff:ff:ff promiscuity 0 
    vxlan id 42 remote 10.2.3.4 dev eth0 srcport 32768 61000 dstport 256 ageing 300 
ip -d link show vx1
65: vx1: <BROADCAST,MULTICAST> mtu 1450 qdisc noop state DOWN mode DEFAULT group default 
    link/ether d2:7e:e8:0d:7e:06 brd ff:ff:ff:ff:ff:ff promiscuity 0 
    vxlan id 42 remote 10.2.3.4 dev eth0 srcport 32768 61000 dstport 512 ageing 300 
ip -d link show vx1
65: vx1: <BROADCAST,MULTICAST> mtu 1450 qdisc noop state DOWN mode DEFAULT group default 
    link/ether d2:7e:e8:0d:7e:06 brd ff:ff:ff:ff:ff:ff promiscuity 0 
    vxlan id 42 remote 10.2.3.4 dev eth0 srcport 32768 61000 dstport 768 ageing 300 

The port I observe varies in the real interface from 256, 512, and finally 768

ip a add xx.xx.xx.xx peer yy.yy.yy.yy analog

Hi, via iproute2 i can add address via ip a add xx.xx.xx.xx peer yy.yy.yy.yy dev zzz

how can i deal with this using this package? Also can you provide info about netlink message that sent in this case?

go get error

I'm getting the go get error below:

lab@ubu10:~/devel$ go get github.com/vishvananda/netlink
# github.com/vishvananda/netlink
nexthop/src/github.com/vishvananda/netlink/bpf_linux.go: In function ‘load_simple_bpf’:
nexthop/src/github.com/vishvananda/netlink/bpf_linux.go:33:12: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   .insns = (__u64)&insns,
            ^
nexthop/src/github.com/vishvananda/netlink/bpf_linux.go:34:14: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   .license = (__u64)&license,
              ^
lab@ubu10:~/devel$
lab@ubu10:~/devel$ go version
go version go1.6 linux/386
lab@ubu10:~/devel$

Undefined type

ubuntu:~/netlink|master⇒  go get github.com/vishvananda/netlink
# github.com/vishvananda/netlink
../gopath/src/github.com/vishvananda/netlink/link_linux.go:893: undefined: NewBond

RouteGet inconsistency

When I run

package main

import (
        "fmt"
        "net"
        "github.com/vishvananda/netlink"
)

func main() {
        ip, _, _ := net.ParseCIDR("2404:9400:1:9c4::/64")
        routes, err := netlink.RouteGet(ip)
        if err != nil {
                fmt.Println(err)
                return
        }
        for _, route := range routes {
                fmt.Printf("%v\n", route)
        }
}

I see: {Ifindex: 1 Dst: 2404:9400:1:9c4::/128 Src: 2404:9400:1:9c4::1 Gw: <nil> Flags: [] Table: 255}

(Ifindex 1 is the loopback interface)

yet when I run ip route get 2404:9400:1:9c4::/64 from the command line, I get no result.

(Centos 7 Linux. Full route table can be seen here)

netlink.LinkSetName is hung for ever, never coming out....

netlink.LinkSetName(iface, i.SrcName()) , This is never returning and waiting indefinitely at
nr, _, err := syscall.Recvfrom(s.fd, rb, 0) ....Above situation is not happening every time...but it is happening at some time in a production environment...

did you guys come across this problem ? is there a way we can timeout here ?

kernel version:- 3.19.0-58-generic #64~14.04.1-Ubuntu

Provide netlink debugging tool

It would be very convenient to also ship some helper functions that would allow debugging netlink messages while hacking on this library.

I have personally being shelling out a bit to check that the library features I am adding were on par with tc as well as dumping the netlink messages in hexa in order to troubleshoot #57 for instance. To do this, I have been using a few functions into a separate file a relied on printing out stuff.

I would like to see some helper functions in netlink so they can be re-used across the code base when needed.
Something that could be handy too, is to gate debugging messages behind an environment variable a la https://www.infradead.org/~tgr/libnl/doc/core.html#_debugging, allowing debugging both while developing or when running a binary.

What are your thoughts on that? I would be happy to hack on it when time permits but would like to get to a concensus first.

For now, I am using https://gist.github.com/chantra/6f2d74e3bc38aadcdc1e which is good enough to get me going.

fatal error

netlink.RouteAdd(&netlink.Route{LinkIndex: 2, Dst: nil})

How can i add default route ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.