{"id":13396816,"url":"https://github.com/vishvananda/netlink","last_synced_at":"2026-04-05T17:36:26.237Z","repository":{"id":20256760,"uuid":"23529571","full_name":"vishvananda/netlink","owner":"vishvananda","description":"Simple netlink library for go.","archived":false,"fork":false,"pushed_at":"2024-10-22T03:13:24.000Z","size":1494,"stargazers_count":2846,"open_issues_count":209,"forks_count":744,"subscribers_count":62,"default_branch":"main","last_synced_at":"2024-10-25T05:21:51.306Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vishvananda.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-01T03:28:37.000Z","updated_at":"2024-10-22T16:50:21.000Z","dependencies_parsed_at":"2023-02-19T12:31:16.154Z","dependency_job_id":"90880e46-228f-4a83-9280-3967d352db9f","html_url":"https://github.com/vishvananda/netlink","commit_stats":{"total_commits":693,"total_committers":294,"mean_commits":2.357142857142857,"dds":0.8888888888888888,"last_synced_commit":"976bd8de7d8167e548320e1dd74e0b0f494577dd"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishvananda%2Fnetlink","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishvananda%2Fnetlink/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishvananda%2Fnetlink/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishvananda%2Fnetlink/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vishvananda","download_url":"https://codeload.github.com/vishvananda/netlink/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243500194,"owners_count":20300756,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:01:03.760Z","updated_at":"2025-12-17T02:25:00.660Z","avatar_url":"https://github.com/vishvananda.png","language":"Go","readme":"# netlink - netlink library for go #\n\n![Build Status](https://github.com/vishvananda/netlink/actions/workflows/main.yml/badge.svg) [![GoDoc](https://godoc.org/github.com/vishvananda/netlink?status.svg)](https://godoc.org/github.com/vishvananda/netlink)\n\nThe netlink package provides a simple netlink library for go. Netlink\nis the interface a user-space program in linux uses to communicate with\nthe kernel. It can be used to add and remove interfaces, set ip addresses\nand routes, and configure ipsec. Netlink communication requires elevated\nprivileges, so in most cases this code needs to be run as root. Since\nlow-level netlink messages are inscrutable at best, the library attempts\nto provide an api that is loosely modeled on the CLI provided by iproute2.\nActions like `ip link add` will be accomplished via a similarly named\nfunction like AddLink(). This library began its life as a fork of the\nnetlink functionality in\n[docker/libcontainer](https://github.com/docker/libcontainer) but was\nheavily rewritten to improve testability, performance, and to add new\nfunctionality like ipsec xfrm handling.\n\n## Local Build and Test ##\n\nYou can use go get command:\n\n    go get github.com/vishvananda/netlink\n\nTesting dependencies:\n\n    go get github.com/vishvananda/netns\n\nTesting (requires root):\n\n    sudo -E go test github.com/vishvananda/netlink\n\n## Examples ##\n\nAdd a new bridge and add eth1 into it:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/vishvananda/netlink\"\n)\n\nfunc main() {\n    la := netlink.NewLinkAttrs()\n    la.Name = \"foo\"\n    mybridge := \u0026netlink.Bridge{LinkAttrs: la}\n    err := netlink.LinkAdd(mybridge)\n    if err != nil  {\n        fmt.Printf(\"could not add %s: %v\\n\", la.Name, err)\n    }\n    eth1, _ := netlink.LinkByName(\"eth1\")\n    netlink.LinkSetMaster(eth1, mybridge)\n}\n\n```\nNote `NewLinkAttrs` constructor, it sets default values in structure. For now\nit sets only `TxQLen` to `-1`, so kernel will set default by itself. If you're\nusing simple initialization(`LinkAttrs{Name: \"foo\"}`) `TxQLen` will be set to\n`0` unless you specify it like `LinkAttrs{Name: \"foo\", TxQLen: 1000}`.\n\nAdd a new ip address to loopback:\n\n```go\npackage main\n\nimport (\n    \"github.com/vishvananda/netlink\"\n)\n\nfunc main() {\n    lo, _ := netlink.LinkByName(\"lo\")\n    addr, _ := netlink.ParseAddr(\"169.254.169.254/32\")\n    netlink.AddrAdd(lo, addr)\n}\n\n```\n\n## Future Work ##\n\nMany pieces of netlink are not yet fully supported in the high-level\ninterface. Aspects of virtually all of the high-level objects don't exist.\nMany of the underlying primitives are there, so its a matter of putting\nthe right fields into the high-level objects and making sure that they\nare serialized and deserialized correctly in the Add and List methods.\n\nThere are also a few pieces of low level netlink functionality that still\nneed to be implemented. Routing rules are not in place and some of the\nmore advanced link types. Hopefully there is decent structure and testing\nin place to make these fairly straightforward to add.\n\n","funding_links":[],"categories":["Library","Misc","Go","🥧 Browse Series: 52 articles"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvishvananda%2Fnetlink","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvishvananda%2Fnetlink","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvishvananda%2Fnetlink/lists"}