forked from aws/amazon-vpc-cni-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
netlink.go
124 lines (103 loc) · 3.69 KB
/
netlink.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package netlinkwrapper
import "github.com/vishvananda/netlink"
// NetLink wraps methods used from the vishvananda/netlink package
type NetLink interface {
// LinkByName gets a link object given the device name
LinkByName(name string) (netlink.Link, error)
// LinkSetNsFd is equivalent to `ip link set $link netns $ns`
LinkSetNsFd(link netlink.Link, fd int) error
// ParseAddr parses an address string
ParseAddr(s string) (*netlink.Addr, error)
// AddrAdd is equivalent to `ip addr add $addr dev $link`
AddrAdd(link netlink.Link, addr *netlink.Addr) error
// AddrList is equivalent to `ip addr show `
AddrList(link netlink.Link, family int) ([]netlink.Addr, error)
// LinkAdd is equivalent to `ip link add`
LinkAdd(link netlink.Link) error
// LinkSetUp is equivalent to `ip link set $link up`
LinkSetUp(link netlink.Link) error
// LinkList is equivalent to: `ip link show`
LinkList() ([]netlink.Link, error)
// LinkSetDown is equivalent to: `ip link set $link down`
LinkSetDown(link netlink.Link) error
// RouteList gets a list of routes in the system.
RouteList(link netlink.Link, family int) ([]netlink.Route, error)
// RouteAdd will add a route to the route table
RouteAdd(route *netlink.Route) error
// RouteDel is equivalent to `ip route del`
RouteDel(route *netlink.Route) error
NeighAdd(neigh *netlink.Neigh) error
LinkDel(link netlink.Link) error
NewRule() *netlink.Rule
RuleDel(rule *netlink.Rule) error
RuleAdd(rule *netlink.Rule) error
}
type netLink struct {
}
// NewNetLink creates a new NetLink object
func NewNetLink() NetLink {
return &netLink{}
}
func (*netLink) LinkAdd(link netlink.Link) error {
return netlink.LinkAdd(link)
}
func (*netLink) LinkByName(name string) (netlink.Link, error) {
return netlink.LinkByName(name)
}
func (*netLink) LinkSetNsFd(link netlink.Link, fd int) error {
return netlink.LinkSetNsFd(link, fd)
}
func (*netLink) ParseAddr(s string) (*netlink.Addr, error) {
return netlink.ParseAddr(s)
}
func (*netLink) AddrAdd(link netlink.Link, addr *netlink.Addr) error {
return netlink.AddrAdd(link, addr)
}
func (*netLink) LinkSetUp(link netlink.Link) error {
return netlink.LinkSetUp(link)
}
func (*netLink) LinkList() ([]netlink.Link, error) {
return netlink.LinkList()
}
func (*netLink) LinkSetDown(link netlink.Link) error {
return netlink.LinkSetDown(link)
}
func (*netLink) RouteList(link netlink.Link, family int) ([]netlink.Route, error) {
return netlink.RouteList(link, family)
}
func (*netLink) RouteAdd(route *netlink.Route) error {
return netlink.RouteAdd(route)
}
func (*netLink) RouteDel(route *netlink.Route) error {
return netlink.RouteDel(route)
}
func (*netLink) AddrList(link netlink.Link, family int) ([]netlink.Addr, error) {
return netlink.AddrList(link, family)
}
func (*netLink) NeighAdd(neigh *netlink.Neigh) error {
return netlink.NeighAdd(neigh)
}
func (*netLink) LinkDel(link netlink.Link) error {
return netlink.LinkDel(link)
}
func (*netLink) NewRule() *netlink.Rule {
return netlink.NewRule()
}
func (*netLink) RuleDel(rule *netlink.Rule) error {
return netlink.RuleDel(rule)
}
func (*netLink) RuleAdd(rule *netlink.Rule) error {
return netlink.RuleAdd(rule)
}