Skip to content

Commit

Permalink
temporarily rename module to github.com/tailscale/netlink
Browse files Browse the repository at this point in the history
This allows Tailscale to use this module while we wait for upstream PR to be merged.
See vishvananda#1006

Updates vishvananda#710

Signed-off-by: Percy Wegmann <percy@tailscale.com>
  • Loading branch information
oxtoacart committed Aug 22, 2024
1 parent f616481 commit a71aabb
Show file tree
Hide file tree
Showing 44 changed files with 157 additions and 151 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $(call goroot,$(DEPS)):

.PHONY: $(call testdirs,$(DIRS))
$(call testdirs,$(DIRS)):
go test -test.exec sudo -test.parallel 4 -timeout 60s -test.v github.com/vishvananda/netlink/$@
go test -test.exec sudo -test.parallel 4 -timeout 60s -test.v github.com/tailscale/netlink/$@

$(call fmt,$(call testdirs,$(DIRS))):
! gofmt -l $(subst fmt-,,$@)/*.go | grep -q .
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# netlink - netlink library for go #

![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)
![Build Status](https://github.com/tailscale/netlink/actions/workflows/main.yml/badge.svg) [![GoDoc](https://godoc.org/github.com/tailscale/netlink?status.svg)](https://godoc.org/github.com/tailscale/netlink)

The netlink package provides a simple netlink library for go. Netlink
is the interface a user-space program in linux uses to communicate with
Expand All @@ -20,15 +20,15 @@ functionality like ipsec xfrm handling.

You can use go get command:

go get github.com/vishvananda/netlink
go get github.com/tailscale/netlink

Testing dependencies:

go get github.com/vishvananda/netns

Testing (requires root):

sudo -E go test github.com/vishvananda/netlink
sudo -E go test github.com/tailscale/netlink

## Examples ##

Expand All @@ -39,7 +39,7 @@ package main

import (
"fmt"
"github.com/vishvananda/netlink"
"github.com/tailscale/netlink"
)

func main() {
Expand All @@ -66,7 +66,7 @@ Add a new ip address to loopback:
package main

import (
"github.com/vishvananda/netlink"
"github.com/tailscale/netlink"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion addr_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"syscall"

"github.com/vishvananda/netlink/nl"
"github.com/tailscale/netlink/nl"
"github.com/vishvananda/netns"
"golang.org/x/sys/unix"
)
Expand Down
4 changes: 2 additions & 2 deletions bridge_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package netlink
import (
"fmt"

"github.com/vishvananda/netlink/nl"
"github.com/tailscale/netlink/nl"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -139,7 +139,7 @@ func (h *Handle) bridgeVlanModify(cmd int, link Link, vid, vidEnd uint16, pvid,

vlanEndInfo.Flags |= nl.BRIDGE_VLAN_INFO_RANGE_END
br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanEndInfo.Serialize())
} else {
} else {
br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanInfo.Serialize())
}

Expand Down
2 changes: 1 addition & 1 deletion chain_linux.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package netlink

import (
"github.com/vishvananda/netlink/nl"
"github.com/tailscale/netlink/nl"
"golang.org/x/sys/unix"
)

Expand Down
2 changes: 1 addition & 1 deletion class_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"syscall"

"github.com/vishvananda/netlink/nl"
"github.com/tailscale/netlink/nl"
"golang.org/x/sys/unix"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/ipset-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"os"
"sort"

"github.com/vishvananda/netlink"
"github.com/tailscale/netlink"
)

type command struct {
Expand Down
27 changes: 15 additions & 12 deletions conntrack_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net"
"time"

"github.com/vishvananda/netlink/nl"
"github.com/tailscale/netlink/nl"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -196,10 +196,11 @@ type ProtoInfo interface {
type ProtoInfoTCP struct {
State uint8
}

// Protocol returns "tcp".
func (*ProtoInfoTCP) Protocol() string {return "tcp"}
func (*ProtoInfoTCP) Protocol() string { return "tcp" }
func (p *ProtoInfoTCP) toNlData() ([]*nl.RtAttr, error) {
ctProtoInfo := nl.NewRtAttr(unix.NLA_F_NESTED | nl.CTA_PROTOINFO, []byte{})
ctProtoInfo := nl.NewRtAttr(unix.NLA_F_NESTED|nl.CTA_PROTOINFO, []byte{})
ctProtoInfoTCP := nl.NewRtAttr(unix.NLA_F_NESTED|nl.CTA_PROTOINFO_TCP, []byte{})
ctProtoInfoTCPState := nl.NewRtAttr(nl.CTA_PROTOINFO_TCP_STATE, nl.Uint8Attr(p.State))
ctProtoInfoTCP.AddChild(ctProtoInfoTCPState)
Expand All @@ -209,14 +210,16 @@ func (p *ProtoInfoTCP) toNlData() ([]*nl.RtAttr, error) {
}

// ProtoInfoSCTP only supports the protocol name.
type ProtoInfoSCTP struct {}
type ProtoInfoSCTP struct{}

// Protocol returns "sctp".
func (*ProtoInfoSCTP) Protocol() string {return "sctp"}
func (*ProtoInfoSCTP) Protocol() string { return "sctp" }

// ProtoInfoDCCP only supports the protocol name.
type ProtoInfoDCCP struct {}
type ProtoInfoDCCP struct{}

// Protocol returns "dccp".
func (*ProtoInfoDCCP) Protocol() string {return "dccp"}
func (*ProtoInfoDCCP) Protocol() string { return "dccp" }

// The full conntrack flow structure is very complicated and can be found in the file:
// http://git.netfilter.org/libnetfilter_conntrack/tree/include/internal/object.h
Expand Down Expand Up @@ -258,7 +261,7 @@ func (t *IPTuple) toNlData(family uint8) ([]*nl.RtAttr, error) {
ctTupleProtoSrcPort := nl.NewRtAttr(nl.CTA_PROTO_SRC_PORT, nl.BEUint16Attr(t.SrcPort))
ctTupleProto.AddChild(ctTupleProtoSrcPort)
ctTupleProtoDstPort := nl.NewRtAttr(nl.CTA_PROTO_DST_PORT, nl.BEUint16Attr(t.DstPort))
ctTupleProto.AddChild(ctTupleProtoDstPort, )
ctTupleProto.AddChild(ctTupleProtoDstPort)

return []*nl.RtAttr{ctTupleIP, ctTupleProto}, nil
}
Expand Down Expand Up @@ -335,7 +338,7 @@ func (s *ConntrackFlow) toNlData() ([]*nl.RtAttr, error) {
// <len, CTA_TIMEOUT>
// <BEuint64>
// <len, NLA_F_NESTED|CTA_PROTOINFO>

// CTA_TUPLE_ORIG
ctTupleOrig := nl.NewRtAttr(unix.NLA_F_NESTED|nl.CTA_TUPLE_ORIG, nil)
forwardFlowAttrs, err := s.Forward.toNlData(s.FamilyType)
Expand Down Expand Up @@ -518,12 +521,12 @@ func parseTimeStamp(r *bytes.Reader, readSize uint16) (tstart, tstop uint64) {

func parseProtoInfoTCPState(r *bytes.Reader) (s uint8) {
binary.Read(r, binary.BigEndian, &s)
r.Seek(nl.SizeofNfattr - 1, seekCurrent)
r.Seek(nl.SizeofNfattr-1, seekCurrent)
return s
}

// parseProtoInfoTCP reads the entire nested protoinfo structure, but only parses the state attr.
func parseProtoInfoTCP(r *bytes.Reader, attrLen uint16) (*ProtoInfoTCP) {
func parseProtoInfoTCP(r *bytes.Reader, attrLen uint16) *ProtoInfoTCP {
p := new(ProtoInfoTCP)
bytesRead := 0
for bytesRead < int(attrLen) {
Expand Down Expand Up @@ -637,7 +640,7 @@ func parseRawData(data []byte) *ConntrackFlow {
switch t {
case nl.CTA_MARK:
s.Mark = parseConnectionMark(reader)
case nl.CTA_LABELS:
case nl.CTA_LABELS:
s.Labels = parseConnectionLabels(reader)
case nl.CTA_TIMEOUT:
s.TimeOut = parseTimeOut(reader)
Expand Down
Loading

0 comments on commit a71aabb

Please sign in to comment.