Skip to content

Commit

Permalink
Merge pull request #59 from fako1024/58-support-for-ipv6-tunnels-link…
Browse files Browse the repository at this point in the history
…-types-769-823

[feature] Add support for IPv6 GRE tunnel link types 769 & 823
  • Loading branch information
fako1024 committed Aug 23, 2023
2 parents a7226e9 + 27e96ac commit cc1d3f7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions link/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,37 @@ const (
// TypePPP denotes a link of type ARPHRD_PPP
TypePPP Type = 512

// TypeIP6IP6 denotes a link of type ARPHRD_TUNNEL6
TypeIP6IP6 Type = 769

// TypeGRE denotes a link of type ARPHRD_IPGRE
TypeGRE Type = 778

// TypeGRE6 denotes a link of type ARPHRD_IP6GRE
TypeGRE6 Type = 823

// TypeNone denotes a link of type ARPHRD_NONE:
// Tunnel / anything else (confirmed: Wireguard, OpenVPN)
TypeNone Type = 65534
)

// IpHeaderOffset returns the link / interface specific payload offset for the IP header
// IPHeaderOffset returns the link / interface specific payload offset for the IP header
// c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/if_arp.h
func (l Type) IPHeaderOffset() byte {
switch l {
case TypeEthernet,
TypeLoopback:
return IPLayerOffsetEthernet
case TypePPP,
TypeIP6IP6,
TypeGRE,
TypeGRE6,
TypeNone:
return 0
}

// Panic if unknown
panic(fmt.Sprintf("LinkType %d not supported (yet)", l))
panic(fmt.Sprintf("LinkType %d not supported by slimcap (yet), please open a GitHub issue", l))
}

// BPFFilter returns the link / interface specific raw BPF instructions to filter for valid packets only
Expand All @@ -82,13 +90,15 @@ func (l Type) BPFFilter() func(snapLen int) []bpf.RawInstruction {
TypeLoopback:
return bpfInstructionsLinkTypeEther
case TypePPP,
TypeIP6IP6,
TypeGRE,
TypeGRE6,
TypeNone:
return bpfInstructionsLinkTypeRaw
}

// Panic if unknown
panic(fmt.Sprintf("LinkType %d not supported (yet)", l))
panic(fmt.Sprintf("LinkType %d not supported by slimcap (yet), please open a GitHub issue", l))
}

// Link denotes a link, i.e. an interface (wrapped) and its link type
Expand Down

0 comments on commit cc1d3f7

Please sign in to comment.