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

..25-Apr-2016-

nl/H25-Apr-2016-1,5761,112

.travis.ymlH A D25-Apr-201666 43

LICENSEH A D25-Apr-201610.5 KiB193161

MakefileH A D25-Apr-2016687 3021

README.mdH A D25-Apr-20162.9 KiB9066

addr.goH A D25-Apr-2016963 4431

addr_linux.goH A D25-Apr-20163 KiB12996

filter.goH A D25-Apr-20161.2 KiB5638

filter_linux.goH A D25-Apr-20164.9 KiB192165

link.goH A D25-Apr-20164 KiB224160

link_linux.goH A D25-Apr-201619.7 KiB751599

neigh.goH A D25-Apr-2016400 2317

neigh_linux.goH A D25-Apr-20163.9 KiB190144

netlink.goH A D25-Apr-20161.3 KiB4020

netlink_unspecified.goH A D25-Apr-20162.5 KiB144106

protinfo.goH A D25-Apr-2016946 5446

protinfo_linux.goH A D25-Apr-20161.4 KiB6156

qdisc.goH A D25-Apr-20162.8 KiB139102

qdisc_linux.goH A D25-Apr-20166 KiB264222

route.goH A D25-Apr-2016847 3625

route_linux.goH A D25-Apr-20165.5 KiB226181

xfrm.goH A D25-Apr-20161.2 KiB6555

xfrm_policy.goH A D25-Apr-20161.1 KiB6046

xfrm_policy_linux.goH A D25-Apr-20163.6 KiB128100

xfrm_state.goH A D25-Apr-20161.1 KiB5441

xfrm_state_linux.goH A D25-Apr-20164.9 KiB182149

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 provied 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    "net"
42    "github.com/vishvananda/netlink"
43)
44
45func main() {
46    la := netlink.NewLinkAttrs()
47    la.Name = "foo"
48    mybridge := &netlink.Bridge{la}}
49    _ := netlink.LinkAdd(mybridge)
50    eth1, _ := netlink.LinkByName("eth1")
51    netlink.LinkSetMaster(eth1, mybridge)
52}
53
54```
55Note `NewLinkAttrs` constructor, it sets default values in structure. For now
56it sets only `TxQLen` to `-1`, so kernel will set default by itself. If you're
57using simple initialization(`LinkAttrs{Name: "foo"}`) `TxQLen` will be set to
58`0` unless you specify it like `LinkAttrs{Name: "foo", TxQLen: 1000}`.
59
60Add a new ip address to loopback:
61
62```go
63package main
64
65import (
66    "net"
67    "github.com/vishvananda/netlink"
68)
69
70func main() {
71    lo, _ := netlink.LinkByName("lo")
72    addr, _ := netlink.ParseAddr("169.254.169.254/32")
73    netlink.AddrAdd(lo, addr)
74}
75
76```
77
78## Future Work ##
79
80Many pieces of netlink are not yet fully supported in the high-level
81interface. Aspects of virtually all of the high-level objects don't exist.
82Many of the underlying primitives are there, so its a matter of putting
83the right fields into the high-level objects and making sure that they
84are serialized and deserialized correctly in the Add and List methods.
85
86There are also a few pieces of low level netlink functionality that still
87need to be implemented. Routing rules are not in place and some of the
88more advanced link types. Hopefully there is decent structure and testing
89in place to make these fairly straightforward to add.
90