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

..03-May-2022-

nl/H16-Mar-2018-4,7773,582

.travis.ymlH A D16-Mar-2018474 1413

CHANGELOG.mdH A D16-Mar-201859 53

LICENSEH A D16-Mar-201810.5 KiB193161

MakefileH A D16-Mar-2018758 3122

README.mdH A D16-Mar-20183 KiB9368

addr.goH A D16-Mar-20181.3 KiB5742

addr_linux.goH A D16-Mar-20189.3 KiB355276

addr_test.goH A D16-Mar-20186.3 KiB288231

bpf_linux.goH A D16-Mar-20181.1 KiB5446

bridge_linux.goH A D16-Mar-20183.6 KiB11689

bridge_linux_test.goH A D16-Mar-20181.9 KiB7874

class.goH A D16-Mar-20181.6 KiB7958

class_linux.goH A D16-Mar-20186.6 KiB256194

class_test.goH A D16-Mar-20189.1 KiB426362

conntrack_linux.goH A D16-Mar-201812.7 KiB372226

conntrack_test.goH A D16-Mar-201811.4 KiB402296

conntrack_unspecified.goH A D16-Mar-20182.1 KiB5423

filter.goH A D16-Mar-20185.8 KiB289233

filter_linux.goH A D16-Mar-201817.1 KiB640568

filter_test.goH A D16-Mar-201814.9 KiB731674

fou.goH A D16-Mar-2018436 2214

fou_linux.goH A D16-Mar-20183.8 KiB216164

fou_test.goH A D16-Mar-20182.6 KiB11079

fou_unspecified.goH A D16-Mar-2018219 1610

genetlink_linux.goH A D16-Mar-20183.7 KiB169153

genetlink_unspecified.goH A D16-Mar-2018480 2616

gtp_linux.goH A D16-Mar-20186.7 KiB240218

gtp_test.goH A D16-Mar-20182.1 KiB117109

handle_linux.goH A D16-Mar-20184.1 KiB145103

handle_test.goH A D16-Mar-20187.4 KiB369324

handle_unspecified.goH A D16-Mar-20185.4 KiB259191

ioctl_linux.goH A D16-Mar-20182.4 KiB9963

link.goH A D16-Mar-201817.5 KiB847677

link_linux.goH A D16-Mar-201867.4 KiB2,3551,902

link_test.goH A D16-Mar-201837.7 KiB1,7451,453

link_tuntap_linux.goH A D16-Mar-2018282 1510

neigh.goH A D16-Mar-2018484 2620

neigh_linux.goH A D16-Mar-20187 KiB290205

neigh_test.goH A D16-Mar-20185.1 KiB254188

netlink.goH A D16-Mar-20181.4 KiB4021

netlink_linux.goH A D16-Mar-2018213 128

netlink_test.goH A D16-Mar-20184.2 KiB183154

netlink_unspecified.goH A D16-Mar-20184.2 KiB226167

order.goH A D16-Mar-2018535 3325

protinfo.goH A D16-Mar-20181.1 KiB5951

protinfo_linux.goH A D16-Mar-20181.8 KiB7668

protinfo_test.goH A D16-Mar-20184.5 KiB162146

qdisc.goH A D16-Mar-20185.9 KiB293229

qdisc_linux.goH A D16-Mar-201817 KiB648542

qdisc_test.goH A D16-Mar-20188.8 KiB459429

route.goH A D16-Mar-20184.1 KiB179156

route_linux.goH A D16-Mar-201822.3 KiB879762

route_test.goH A D16-Mar-201820.8 KiB1,045886

route_unspecified.goH A D16-Mar-2018162 127

rule.goH A D16-Mar-2018831 4336

rule_linux.goH A D16-Mar-20186.1 KiB235200

rule_test.goH A D16-Mar-20181.5 KiB7660

socket.goH A D16-Mar-2018464 2822

socket_linux.goH A D16-Mar-20183.6 KiB160143

socket_test.goH A D16-Mar-20181.3 KiB5950

xfrm.goH A D16-Mar-20181.5 KiB7662

xfrm_monitor_linux.goH A D16-Mar-20181.7 KiB9877

xfrm_monitor_test.goH A D16-Mar-2018783 4029

xfrm_policy.goH A D16-Mar-20181.6 KiB7559

xfrm_policy_linux.goH A D16-Mar-20187.6 KiB257191

xfrm_policy_test.goH A D16-Mar-20183.9 KiB200165

xfrm_state.goH A D16-Mar-20183.7 KiB130107

xfrm_state_linux.goH A D16-Mar-201812.6 KiB458351

xfrm_state_test.goH A D16-Mar-20186.4 KiB292243

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