Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
nl/ | H | 16-Mar-2018 | - | 4,777 | 3,582 | |
.travis.yml | H A D | 16-Mar-2018 | 474 | 14 | 13 | |
CHANGELOG.md | H A D | 16-Mar-2018 | 59 | 5 | 3 | |
LICENSE | H A D | 16-Mar-2018 | 10.5 KiB | 193 | 161 | |
Makefile | H A D | 16-Mar-2018 | 758 | 31 | 22 | |
README.md | H A D | 16-Mar-2018 | 3 KiB | 93 | 68 | |
addr.go | H A D | 16-Mar-2018 | 1.3 KiB | 57 | 42 | |
addr_linux.go | H A D | 16-Mar-2018 | 9.3 KiB | 355 | 276 | |
addr_test.go | H A D | 16-Mar-2018 | 6.3 KiB | 288 | 231 | |
bpf_linux.go | H A D | 16-Mar-2018 | 1.1 KiB | 54 | 46 | |
bridge_linux.go | H A D | 16-Mar-2018 | 3.6 KiB | 116 | 89 | |
bridge_linux_test.go | H A D | 16-Mar-2018 | 1.9 KiB | 78 | 74 | |
class.go | H A D | 16-Mar-2018 | 1.6 KiB | 79 | 58 | |
class_linux.go | H A D | 16-Mar-2018 | 6.6 KiB | 256 | 194 | |
class_test.go | H A D | 16-Mar-2018 | 9.1 KiB | 426 | 362 | |
conntrack_linux.go | H A D | 16-Mar-2018 | 12.7 KiB | 372 | 226 | |
conntrack_test.go | H A D | 16-Mar-2018 | 11.4 KiB | 402 | 296 | |
conntrack_unspecified.go | H A D | 16-Mar-2018 | 2.1 KiB | 54 | 23 | |
filter.go | H A D | 16-Mar-2018 | 5.8 KiB | 289 | 233 | |
filter_linux.go | H A D | 16-Mar-2018 | 17.1 KiB | 640 | 568 | |
filter_test.go | H A D | 16-Mar-2018 | 14.9 KiB | 731 | 674 | |
fou.go | H A D | 16-Mar-2018 | 436 | 22 | 14 | |
fou_linux.go | H A D | 16-Mar-2018 | 3.8 KiB | 216 | 164 | |
fou_test.go | H A D | 16-Mar-2018 | 2.6 KiB | 110 | 79 | |
fou_unspecified.go | H A D | 16-Mar-2018 | 219 | 16 | 10 | |
genetlink_linux.go | H A D | 16-Mar-2018 | 3.7 KiB | 169 | 153 | |
genetlink_unspecified.go | H A D | 16-Mar-2018 | 480 | 26 | 16 | |
gtp_linux.go | H A D | 16-Mar-2018 | 6.7 KiB | 240 | 218 | |
gtp_test.go | H A D | 16-Mar-2018 | 2.1 KiB | 117 | 109 | |
handle_linux.go | H A D | 16-Mar-2018 | 4.1 KiB | 145 | 103 | |
handle_test.go | H A D | 16-Mar-2018 | 7.4 KiB | 369 | 324 | |
handle_unspecified.go | H A D | 16-Mar-2018 | 5.4 KiB | 259 | 191 | |
ioctl_linux.go | H A D | 16-Mar-2018 | 2.4 KiB | 99 | 63 | |
link.go | H A D | 16-Mar-2018 | 17.5 KiB | 847 | 677 | |
link_linux.go | H A D | 16-Mar-2018 | 67.4 KiB | 2,355 | 1,902 | |
link_test.go | H A D | 16-Mar-2018 | 37.7 KiB | 1,745 | 1,453 | |
link_tuntap_linux.go | H A D | 16-Mar-2018 | 282 | 15 | 10 | |
neigh.go | H A D | 16-Mar-2018 | 484 | 26 | 20 | |
neigh_linux.go | H A D | 16-Mar-2018 | 7 KiB | 290 | 205 | |
neigh_test.go | H A D | 16-Mar-2018 | 5.1 KiB | 254 | 188 | |
netlink.go | H A D | 16-Mar-2018 | 1.4 KiB | 40 | 21 | |
netlink_linux.go | H A D | 16-Mar-2018 | 213 | 12 | 8 | |
netlink_test.go | H A D | 16-Mar-2018 | 4.2 KiB | 183 | 154 | |
netlink_unspecified.go | H A D | 16-Mar-2018 | 4.2 KiB | 226 | 167 | |
order.go | H A D | 16-Mar-2018 | 535 | 33 | 25 | |
protinfo.go | H A D | 16-Mar-2018 | 1.1 KiB | 59 | 51 | |
protinfo_linux.go | H A D | 16-Mar-2018 | 1.8 KiB | 76 | 68 | |
protinfo_test.go | H A D | 16-Mar-2018 | 4.5 KiB | 162 | 146 | |
qdisc.go | H A D | 16-Mar-2018 | 5.9 KiB | 293 | 229 | |
qdisc_linux.go | H A D | 16-Mar-2018 | 17 KiB | 648 | 542 | |
qdisc_test.go | H A D | 16-Mar-2018 | 8.8 KiB | 459 | 429 | |
route.go | H A D | 16-Mar-2018 | 4.1 KiB | 179 | 156 | |
route_linux.go | H A D | 16-Mar-2018 | 22.3 KiB | 879 | 762 | |
route_test.go | H A D | 16-Mar-2018 | 20.8 KiB | 1,045 | 886 | |
route_unspecified.go | H A D | 16-Mar-2018 | 162 | 12 | 7 | |
rule.go | H A D | 16-Mar-2018 | 831 | 43 | 36 | |
rule_linux.go | H A D | 16-Mar-2018 | 6.1 KiB | 235 | 200 | |
rule_test.go | H A D | 16-Mar-2018 | 1.5 KiB | 76 | 60 | |
socket.go | H A D | 16-Mar-2018 | 464 | 28 | 22 | |
socket_linux.go | H A D | 16-Mar-2018 | 3.6 KiB | 160 | 143 | |
socket_test.go | H A D | 16-Mar-2018 | 1.3 KiB | 59 | 50 | |
xfrm.go | H A D | 16-Mar-2018 | 1.5 KiB | 76 | 62 | |
xfrm_monitor_linux.go | H A D | 16-Mar-2018 | 1.7 KiB | 98 | 77 | |
xfrm_monitor_test.go | H A D | 16-Mar-2018 | 783 | 40 | 29 | |
xfrm_policy.go | H A D | 16-Mar-2018 | 1.6 KiB | 75 | 59 | |
xfrm_policy_linux.go | H A D | 16-Mar-2018 | 7.6 KiB | 257 | 191 | |
xfrm_policy_test.go | H A D | 16-Mar-2018 | 3.9 KiB | 200 | 165 | |
xfrm_state.go | H A D | 16-Mar-2018 | 3.7 KiB | 130 | 107 | |
xfrm_state_linux.go | H A D | 16-Mar-2018 | 12.6 KiB | 458 | 351 | |
xfrm_state_test.go | H A D | 16-Mar-2018 | 6.4 KiB | 292 | 243 |
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