• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-Feb-2021-

nl/H03-Feb-2021-4,0392,941

.gitignoreH A D03-Feb-20217 21

.travis.ymlH A D03-Feb-2021591 2019

CHANGELOG.mdH A D03-Feb-202159 53

LICENSEH A D03-Feb-202110.5 KiB193161

MakefileH A D03-Feb-2021758 3122

README.mdH A D03-Feb-20213 KiB9368

addr.goH A D03-Feb-20211.3 KiB5742

addr_linux.goH A D03-Feb-202111.3 KiB418300

bpf_linux.goH A D03-Feb-20211.1 KiB5446

bridge_linux.goH A D03-Feb-20213.5 KiB11386

class.goH A D03-Feb-20215.5 KiB212143

class_linux.goH A D03-Feb-202110.4 KiB385309

conntrack_linux.goH A D03-Feb-202113.6 KiB395247

conntrack_unspecified.goH A D03-Feb-20212.1 KiB5423

devlink_linux.goH A D03-Feb-20217.2 KiB273221

filter.goH A D03-Feb-20216.1 KiB325267

filter_linux.goH A D03-Feb-202122.8 KiB808718

fou.goH A D03-Feb-2021436 2214

fou_linux.goH A D03-Feb-20213.8 KiB212161

fou_unspecified.goH A D03-Feb-2021219 1610

genetlink_linux.goH A D03-Feb-20213.8 KiB172156

genetlink_unspecified.goH A D03-Feb-2021480 2616

go.modH A D03-Feb-2021178 96

go.sumH A D03-Feb-2021438 54

gtp_linux.goH A D03-Feb-20216.7 KiB240218

handle_linux.goH A D03-Feb-20214.1 KiB145103

handle_unspecified.goH A D03-Feb-20215.7 KiB271200

ioctl_linux.goH A D03-Feb-20212.2 KiB9156

link.goH A D03-Feb-202121.9 KiB1,065850

link_linux.goH A D03-Feb-202186.2 KiB3,0192,433

link_tuntap_linux.goH A D03-Feb-2021282 1510

neigh.goH A D03-Feb-2021638 3325

neigh_linux.goH A D03-Feb-202110.9 KiB423316

netlink.goH A D03-Feb-20211.3 KiB4122

netlink_linux.goH A D03-Feb-2021213 128

netlink_unspecified.goH A D03-Feb-20214.4 KiB238176

netns_linux.goH A D03-Feb-20214.4 KiB14278

netns_unspecified.goH A D03-Feb-2021330 2013

order.goH A D03-Feb-2021535 3325

protinfo.goH A D03-Feb-20211.1 KiB6354

protinfo_linux.goH A D03-Feb-20211.8 KiB7567

qdisc.goH A D03-Feb-20217.2 KiB341269

qdisc_linux.goH A D03-Feb-202117.3 KiB669562

rdma_link_linux.goH A D03-Feb-20217.3 KiB265184

route.goH A D03-Feb-20214.1 KiB181158

route_linux.goH A D03-Feb-202128 KiB1,082957

route_unspecified.goH A D03-Feb-2021162 127

rule.goH A D03-Feb-2021831 4336

rule_linux.goH A D03-Feb-20216.1 KiB235200

socket.goH A D03-Feb-2021464 2822

socket_linux.goH A D03-Feb-20213.7 KiB163146

xfrm.goH A D03-Feb-20211.5 KiB7662

xfrm_monitor_linux.goH A D03-Feb-20211.8 KiB10281

xfrm_policy.goH A D03-Feb-20212.1 KiB9777

xfrm_policy_linux.goH A D03-Feb-20218 KiB264197

xfrm_state.goH A D03-Feb-20213.8 KiB132109

xfrm_state_linux.goH A D03-Feb-202112.9 KiB463356

README.md

1# netlink - netlink library for go #
2
3[![Build Status](https://travis-ci.org/vishvananda/netlink.png?branch=master)](https://travis-ci.org/vishvananda/netlink) [![GoDoc](https://godoc.org/github.com/vishvananda/netlink?status.svg)](https://godoc.org/github.com/vishvananda/netlink)
4
5The netlink package provides a simple netlink library for go. Netlink
6is the interface a user-space program in linux uses to communicate with
7the kernel. It can be used to add and remove interfaces, set ip addresses
8and routes, and configure ipsec. Netlink communication requires elevated
9privileges, so in most cases this code needs to be run as root. Since
10low-level netlink messages are inscrutable at best, the library attempts
11to provide an api that is loosely modeled on the CLI provided by iproute2.
12Actions like `ip link add` will be accomplished via a similarly named
13function like AddLink(). This library began its life as a fork of the
14netlink functionality in
15[docker/libcontainer](https://github.com/docker/libcontainer) but was
16heavily rewritten to improve testability, performance, and to add new
17functionality like ipsec xfrm handling.
18
19## Local Build and Test ##
20
21You can use go get command:
22
23    go get github.com/vishvananda/netlink
24
25Testing dependencies:
26
27    go get github.com/vishvananda/netns
28
29Testing (requires root):
30
31    sudo -E go test github.com/vishvananda/netlink
32
33## Examples ##
34
35Add a new bridge and add eth1 into it:
36
37```go
38package main
39
40import (
41    "fmt"
42    "github.com/vishvananda/netlink"
43)
44
45func main() {
46    la := netlink.NewLinkAttrs()
47    la.Name = "foo"
48    mybridge := &netlink.Bridge{LinkAttrs: la}
49    err := netlink.LinkAdd(mybridge)
50    if err != nil  {
51        fmt.Printf("could not add %s: %v\n", la.Name, err)
52    }
53    eth1, _ := netlink.LinkByName("eth1")
54    netlink.LinkSetMaster(eth1, mybridge)
55}
56
57```
58Note `NewLinkAttrs` constructor, it sets default values in structure. For now
59it sets only `TxQLen` to `-1`, so kernel will set default by itself. If you're
60using simple initialization(`LinkAttrs{Name: "foo"}`) `TxQLen` will be set to
61`0` unless you specify it like `LinkAttrs{Name: "foo", TxQLen: 1000}`.
62
63Add a new ip address to loopback:
64
65```go
66package main
67
68import (
69    "github.com/vishvananda/netlink"
70)
71
72func main() {
73    lo, _ := netlink.LinkByName("lo")
74    addr, _ := netlink.ParseAddr("169.254.169.254/32")
75    netlink.AddrAdd(lo, addr)
76}
77
78```
79
80## Future Work ##
81
82Many pieces of netlink are not yet fully supported in the high-level
83interface. Aspects of virtually all of the high-level objects don't exist.
84Many of the underlying primitives are there, so its a matter of putting
85the right fields into the high-level objects and making sure that they
86are serialized and deserialized correctly in the Add and List methods.
87
88There are also a few pieces of low level netlink functionality that still
89need to be implemented. Routing rules are not in place and some of the
90more advanced link types. Hopefully there is decent structure and testing
91in place to make these fairly straightforward to add.
92
93