mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Move tcpip.PacketBuffer and IPTables to stack package.
This is a precursor to be being able to build an intrusive list of PacketBuffers for use in queuing disciplines being implemented. Updates #2214 PiperOrigin-RevId: 302677662
This commit is contained in:
committed by
gVisor bot
parent
a730d74b32
commit
7e4073af12
@@ -22,7 +22,6 @@ go_library(
|
||||
"//pkg/syserr",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/header",
|
||||
"//pkg/tcpip/iptables",
|
||||
"//pkg/tcpip/stack",
|
||||
"//pkg/usermem",
|
||||
],
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/binary"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/iptables"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
|
||||
@@ -37,12 +37,12 @@ type matchMaker interface {
|
||||
// name is the matcher name as stored in the xt_entry_match struct.
|
||||
name() string
|
||||
|
||||
// marshal converts from an iptables.Matcher to an ABI struct.
|
||||
marshal(matcher iptables.Matcher) []byte
|
||||
// marshal converts from an stack.Matcher to an ABI struct.
|
||||
marshal(matcher stack.Matcher) []byte
|
||||
|
||||
// unmarshal converts from the ABI matcher struct to an
|
||||
// iptables.Matcher.
|
||||
unmarshal(buf []byte, filter iptables.IPHeaderFilter) (iptables.Matcher, error)
|
||||
// stack.Matcher.
|
||||
unmarshal(buf []byte, filter stack.IPHeaderFilter) (stack.Matcher, error)
|
||||
}
|
||||
|
||||
// matchMakers maps the name of supported matchers to the matchMaker that
|
||||
@@ -58,7 +58,7 @@ func registerMatchMaker(mm matchMaker) {
|
||||
matchMakers[mm.name()] = mm
|
||||
}
|
||||
|
||||
func marshalMatcher(matcher iptables.Matcher) []byte {
|
||||
func marshalMatcher(matcher stack.Matcher) []byte {
|
||||
matchMaker, ok := matchMakers[matcher.Name()]
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("Unknown matcher of type %T.", matcher))
|
||||
@@ -86,7 +86,7 @@ func marshalEntryMatch(name string, data []byte) []byte {
|
||||
return append(buf, make([]byte, size-len(buf))...)
|
||||
}
|
||||
|
||||
func unmarshalMatcher(match linux.XTEntryMatch, filter iptables.IPHeaderFilter, buf []byte) (iptables.Matcher, error) {
|
||||
func unmarshalMatcher(match linux.XTEntryMatch, filter stack.IPHeaderFilter, buf []byte) (stack.Matcher, error) {
|
||||
matchMaker, ok := matchMakers[match.Name.String()]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unsupported matcher with name %q", match.Name.String())
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/syserr"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/iptables"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
@@ -129,19 +128,19 @@ func GetEntries(t *kernel.Task, stack *stack.Stack, outPtr usermem.Addr, outLen
|
||||
return entries, nil
|
||||
}
|
||||
|
||||
func findTable(stack *stack.Stack, tablename linux.TableName) (iptables.Table, error) {
|
||||
ipt := stack.IPTables()
|
||||
func findTable(stk *stack.Stack, tablename linux.TableName) (stack.Table, error) {
|
||||
ipt := stk.IPTables()
|
||||
table, ok := ipt.Tables[tablename.String()]
|
||||
if !ok {
|
||||
return iptables.Table{}, fmt.Errorf("couldn't find table %q", tablename)
|
||||
return stack.Table{}, fmt.Errorf("couldn't find table %q", tablename)
|
||||
}
|
||||
return table, nil
|
||||
}
|
||||
|
||||
// FillDefaultIPTables sets stack's IPTables to the default tables and
|
||||
// populates them with metadata.
|
||||
func FillDefaultIPTables(stack *stack.Stack) {
|
||||
ipt := iptables.DefaultTables()
|
||||
func FillDefaultIPTables(stk *stack.Stack) {
|
||||
ipt := stack.DefaultTables()
|
||||
|
||||
// In order to fill in the metadata, we have to translate ipt from its
|
||||
// netstack format to Linux's giant-binary-blob format.
|
||||
@@ -154,14 +153,14 @@ func FillDefaultIPTables(stack *stack.Stack) {
|
||||
ipt.Tables[name] = table
|
||||
}
|
||||
|
||||
stack.SetIPTables(ipt)
|
||||
stk.SetIPTables(ipt)
|
||||
}
|
||||
|
||||
// convertNetstackToBinary converts the iptables as stored in netstack to the
|
||||
// format expected by the iptables tool. Linux stores each table as a binary
|
||||
// blob that can only be traversed by parsing a bit, reading some offsets,
|
||||
// jumping to those offsets, parsing again, etc.
|
||||
func convertNetstackToBinary(tablename string, table iptables.Table) (linux.KernelIPTGetEntries, metadata, error) {
|
||||
func convertNetstackToBinary(tablename string, table stack.Table) (linux.KernelIPTGetEntries, metadata, error) {
|
||||
// Return values.
|
||||
var entries linux.KernelIPTGetEntries
|
||||
var meta metadata
|
||||
@@ -234,19 +233,19 @@ func convertNetstackToBinary(tablename string, table iptables.Table) (linux.Kern
|
||||
return entries, meta, nil
|
||||
}
|
||||
|
||||
func marshalTarget(target iptables.Target) []byte {
|
||||
func marshalTarget(target stack.Target) []byte {
|
||||
switch tg := target.(type) {
|
||||
case iptables.AcceptTarget:
|
||||
return marshalStandardTarget(iptables.RuleAccept)
|
||||
case iptables.DropTarget:
|
||||
return marshalStandardTarget(iptables.RuleDrop)
|
||||
case iptables.ErrorTarget:
|
||||
case stack.AcceptTarget:
|
||||
return marshalStandardTarget(stack.RuleAccept)
|
||||
case stack.DropTarget:
|
||||
return marshalStandardTarget(stack.RuleDrop)
|
||||
case stack.ErrorTarget:
|
||||
return marshalErrorTarget(errorTargetName)
|
||||
case iptables.UserChainTarget:
|
||||
case stack.UserChainTarget:
|
||||
return marshalErrorTarget(tg.Name)
|
||||
case iptables.ReturnTarget:
|
||||
return marshalStandardTarget(iptables.RuleReturn)
|
||||
case iptables.RedirectTarget:
|
||||
case stack.ReturnTarget:
|
||||
return marshalStandardTarget(stack.RuleReturn)
|
||||
case stack.RedirectTarget:
|
||||
return marshalRedirectTarget()
|
||||
case JumpTarget:
|
||||
return marshalJumpTarget(tg)
|
||||
@@ -255,7 +254,7 @@ func marshalTarget(target iptables.Target) []byte {
|
||||
}
|
||||
}
|
||||
|
||||
func marshalStandardTarget(verdict iptables.RuleVerdict) []byte {
|
||||
func marshalStandardTarget(verdict stack.RuleVerdict) []byte {
|
||||
nflog("convert to binary: marshalling standard target")
|
||||
|
||||
// The target's name will be the empty string.
|
||||
@@ -316,13 +315,13 @@ func marshalJumpTarget(jt JumpTarget) []byte {
|
||||
|
||||
// translateFromStandardVerdict translates verdicts the same way as the iptables
|
||||
// tool.
|
||||
func translateFromStandardVerdict(verdict iptables.RuleVerdict) int32 {
|
||||
func translateFromStandardVerdict(verdict stack.RuleVerdict) int32 {
|
||||
switch verdict {
|
||||
case iptables.RuleAccept:
|
||||
case stack.RuleAccept:
|
||||
return -linux.NF_ACCEPT - 1
|
||||
case iptables.RuleDrop:
|
||||
case stack.RuleDrop:
|
||||
return -linux.NF_DROP - 1
|
||||
case iptables.RuleReturn:
|
||||
case stack.RuleReturn:
|
||||
return linux.NF_RETURN
|
||||
default:
|
||||
// TODO(gvisor.dev/issue/170): Support Jump.
|
||||
@@ -331,18 +330,18 @@ func translateFromStandardVerdict(verdict iptables.RuleVerdict) int32 {
|
||||
}
|
||||
|
||||
// translateToStandardTarget translates from the value in a
|
||||
// linux.XTStandardTarget to an iptables.Verdict.
|
||||
func translateToStandardTarget(val int32) (iptables.Target, error) {
|
||||
// linux.XTStandardTarget to an stack.Verdict.
|
||||
func translateToStandardTarget(val int32) (stack.Target, error) {
|
||||
// TODO(gvisor.dev/issue/170): Support other verdicts.
|
||||
switch val {
|
||||
case -linux.NF_ACCEPT - 1:
|
||||
return iptables.AcceptTarget{}, nil
|
||||
return stack.AcceptTarget{}, nil
|
||||
case -linux.NF_DROP - 1:
|
||||
return iptables.DropTarget{}, nil
|
||||
return stack.DropTarget{}, nil
|
||||
case -linux.NF_QUEUE - 1:
|
||||
return nil, errors.New("unsupported iptables verdict QUEUE")
|
||||
case linux.NF_RETURN:
|
||||
return iptables.ReturnTarget{}, nil
|
||||
return stack.ReturnTarget{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown iptables verdict %d", val)
|
||||
}
|
||||
@@ -350,7 +349,7 @@ func translateToStandardTarget(val int32) (iptables.Target, error) {
|
||||
|
||||
// SetEntries sets iptables rules for a single table. See
|
||||
// net/ipv4/netfilter/ip_tables.c:translate_table for reference.
|
||||
func SetEntries(stack *stack.Stack, optVal []byte) *syserr.Error {
|
||||
func SetEntries(stk *stack.Stack, optVal []byte) *syserr.Error {
|
||||
// Get the basic rules data (struct ipt_replace).
|
||||
if len(optVal) < linux.SizeOfIPTReplace {
|
||||
nflog("optVal has insufficient size for replace %d", len(optVal))
|
||||
@@ -362,12 +361,12 @@ func SetEntries(stack *stack.Stack, optVal []byte) *syserr.Error {
|
||||
binary.Unmarshal(replaceBuf, usermem.ByteOrder, &replace)
|
||||
|
||||
// TODO(gvisor.dev/issue/170): Support other tables.
|
||||
var table iptables.Table
|
||||
var table stack.Table
|
||||
switch replace.Name.String() {
|
||||
case iptables.TablenameFilter:
|
||||
table = iptables.EmptyFilterTable()
|
||||
case iptables.TablenameNat:
|
||||
table = iptables.EmptyNatTable()
|
||||
case stack.TablenameFilter:
|
||||
table = stack.EmptyFilterTable()
|
||||
case stack.TablenameNat:
|
||||
table = stack.EmptyNatTable()
|
||||
default:
|
||||
nflog("we don't yet support writing to the %q table (gvisor.dev/issue/170)", replace.Name.String())
|
||||
return syserr.ErrInvalidArgument
|
||||
@@ -434,7 +433,7 @@ func SetEntries(stack *stack.Stack, optVal []byte) *syserr.Error {
|
||||
}
|
||||
optVal = optVal[targetSize:]
|
||||
|
||||
table.Rules = append(table.Rules, iptables.Rule{
|
||||
table.Rules = append(table.Rules, stack.Rule{
|
||||
Filter: filter,
|
||||
Target: target,
|
||||
Matchers: matchers,
|
||||
@@ -465,11 +464,11 @@ func SetEntries(stack *stack.Stack, optVal []byte) *syserr.Error {
|
||||
table.Underflows[hk] = ruleIdx
|
||||
}
|
||||
}
|
||||
if ruleIdx := table.BuiltinChains[hk]; ruleIdx == iptables.HookUnset {
|
||||
if ruleIdx := table.BuiltinChains[hk]; ruleIdx == stack.HookUnset {
|
||||
nflog("hook %v is unset.", hk)
|
||||
return syserr.ErrInvalidArgument
|
||||
}
|
||||
if ruleIdx := table.Underflows[hk]; ruleIdx == iptables.HookUnset {
|
||||
if ruleIdx := table.Underflows[hk]; ruleIdx == stack.HookUnset {
|
||||
nflog("underflow %v is unset.", hk)
|
||||
return syserr.ErrInvalidArgument
|
||||
}
|
||||
@@ -478,7 +477,7 @@ func SetEntries(stack *stack.Stack, optVal []byte) *syserr.Error {
|
||||
|
||||
// Add the user chains.
|
||||
for ruleIdx, rule := range table.Rules {
|
||||
target, ok := rule.Target.(iptables.UserChainTarget)
|
||||
target, ok := rule.Target.(stack.UserChainTarget)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
@@ -522,8 +521,8 @@ func SetEntries(stack *stack.Stack, optVal []byte) *syserr.Error {
|
||||
// PREROUTING chain right now, make sure all other chains point to
|
||||
// ACCEPT rules.
|
||||
for hook, ruleIdx := range table.BuiltinChains {
|
||||
if hook != iptables.Input && hook != iptables.Prerouting {
|
||||
if _, ok := table.Rules[ruleIdx].Target.(iptables.AcceptTarget); !ok {
|
||||
if hook != stack.Input && hook != stack.Prerouting {
|
||||
if _, ok := table.Rules[ruleIdx].Target.(stack.AcceptTarget); !ok {
|
||||
nflog("hook %d is unsupported.", hook)
|
||||
return syserr.ErrInvalidArgument
|
||||
}
|
||||
@@ -535,7 +534,7 @@ func SetEntries(stack *stack.Stack, optVal []byte) *syserr.Error {
|
||||
// - There are no chains without an unconditional final rule.
|
||||
// - There are no chains without an unconditional underflow rule.
|
||||
|
||||
ipt := stack.IPTables()
|
||||
ipt := stk.IPTables()
|
||||
table.SetMetadata(metadata{
|
||||
HookEntry: replace.HookEntry,
|
||||
Underflow: replace.Underflow,
|
||||
@@ -543,16 +542,16 @@ func SetEntries(stack *stack.Stack, optVal []byte) *syserr.Error {
|
||||
Size: replace.Size,
|
||||
})
|
||||
ipt.Tables[replace.Name.String()] = table
|
||||
stack.SetIPTables(ipt)
|
||||
stk.SetIPTables(ipt)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// parseMatchers parses 0 or more matchers from optVal. optVal should contain
|
||||
// only the matchers.
|
||||
func parseMatchers(filter iptables.IPHeaderFilter, optVal []byte) ([]iptables.Matcher, error) {
|
||||
func parseMatchers(filter stack.IPHeaderFilter, optVal []byte) ([]stack.Matcher, error) {
|
||||
nflog("set entries: parsing matchers of size %d", len(optVal))
|
||||
var matchers []iptables.Matcher
|
||||
var matchers []stack.Matcher
|
||||
for len(optVal) > 0 {
|
||||
nflog("set entries: optVal has len %d", len(optVal))
|
||||
|
||||
@@ -594,7 +593,7 @@ func parseMatchers(filter iptables.IPHeaderFilter, optVal []byte) ([]iptables.Ma
|
||||
|
||||
// parseTarget parses a target from optVal. optVal should contain only the
|
||||
// target.
|
||||
func parseTarget(filter iptables.IPHeaderFilter, optVal []byte) (iptables.Target, error) {
|
||||
func parseTarget(filter stack.IPHeaderFilter, optVal []byte) (stack.Target, error) {
|
||||
nflog("set entries: parsing target of size %d", len(optVal))
|
||||
if len(optVal) < linux.SizeOfXTEntryTarget {
|
||||
return nil, fmt.Errorf("optVal has insufficient size for entry target %d", len(optVal))
|
||||
@@ -638,11 +637,11 @@ func parseTarget(filter iptables.IPHeaderFilter, optVal []byte) (iptables.Target
|
||||
switch name := errorTarget.Name.String(); name {
|
||||
case errorTargetName:
|
||||
nflog("set entries: error target")
|
||||
return iptables.ErrorTarget{}, nil
|
||||
return stack.ErrorTarget{}, nil
|
||||
default:
|
||||
// User defined chain.
|
||||
nflog("set entries: user-defined target %q", name)
|
||||
return iptables.UserChainTarget{Name: name}, nil
|
||||
return stack.UserChainTarget{Name: name}, nil
|
||||
}
|
||||
|
||||
case redirectTargetName:
|
||||
@@ -659,8 +658,8 @@ func parseTarget(filter iptables.IPHeaderFilter, optVal []byte) (iptables.Target
|
||||
buf = optVal[:linux.SizeOfXTRedirectTarget]
|
||||
binary.Unmarshal(buf, usermem.ByteOrder, &redirectTarget)
|
||||
|
||||
// Copy linux.XTRedirectTarget to iptables.RedirectTarget.
|
||||
var target iptables.RedirectTarget
|
||||
// Copy linux.XTRedirectTarget to stack.RedirectTarget.
|
||||
var target stack.RedirectTarget
|
||||
nfRange := redirectTarget.NfRange
|
||||
|
||||
// RangeSize should be 1.
|
||||
@@ -699,14 +698,14 @@ func parseTarget(filter iptables.IPHeaderFilter, optVal []byte) (iptables.Target
|
||||
return nil, fmt.Errorf("unknown target %q doesn't exist or isn't supported yet.", target.Name.String())
|
||||
}
|
||||
|
||||
func filterFromIPTIP(iptip linux.IPTIP) (iptables.IPHeaderFilter, error) {
|
||||
func filterFromIPTIP(iptip linux.IPTIP) (stack.IPHeaderFilter, error) {
|
||||
if containsUnsupportedFields(iptip) {
|
||||
return iptables.IPHeaderFilter{}, fmt.Errorf("unsupported fields in struct iptip: %+v", iptip)
|
||||
return stack.IPHeaderFilter{}, fmt.Errorf("unsupported fields in struct iptip: %+v", iptip)
|
||||
}
|
||||
if len(iptip.Dst) != header.IPv4AddressSize || len(iptip.DstMask) != header.IPv4AddressSize {
|
||||
return iptables.IPHeaderFilter{}, fmt.Errorf("incorrect length of destination (%d) and/or destination mask (%d) fields", len(iptip.Dst), len(iptip.DstMask))
|
||||
return stack.IPHeaderFilter{}, fmt.Errorf("incorrect length of destination (%d) and/or destination mask (%d) fields", len(iptip.Dst), len(iptip.DstMask))
|
||||
}
|
||||
return iptables.IPHeaderFilter{
|
||||
return stack.IPHeaderFilter{
|
||||
Protocol: tcpip.TransportProtocolNumber(iptip.Protocol),
|
||||
Dst: tcpip.Address(iptip.Dst[:]),
|
||||
DstMask: tcpip.Address(iptip.DstMask[:]),
|
||||
@@ -733,30 +732,30 @@ func containsUnsupportedFields(iptip linux.IPTIP) bool {
|
||||
iptip.InverseFlags&^inverseMask != 0
|
||||
}
|
||||
|
||||
func validUnderflow(rule iptables.Rule) bool {
|
||||
func validUnderflow(rule stack.Rule) bool {
|
||||
if len(rule.Matchers) != 0 {
|
||||
return false
|
||||
}
|
||||
switch rule.Target.(type) {
|
||||
case iptables.AcceptTarget, iptables.DropTarget:
|
||||
case stack.AcceptTarget, stack.DropTarget:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func hookFromLinux(hook int) iptables.Hook {
|
||||
func hookFromLinux(hook int) stack.Hook {
|
||||
switch hook {
|
||||
case linux.NF_INET_PRE_ROUTING:
|
||||
return iptables.Prerouting
|
||||
return stack.Prerouting
|
||||
case linux.NF_INET_LOCAL_IN:
|
||||
return iptables.Input
|
||||
return stack.Input
|
||||
case linux.NF_INET_FORWARD:
|
||||
return iptables.Forward
|
||||
return stack.Forward
|
||||
case linux.NF_INET_LOCAL_OUT:
|
||||
return iptables.Output
|
||||
return stack.Output
|
||||
case linux.NF_INET_POST_ROUTING:
|
||||
return iptables.Postrouting
|
||||
return stack.Postrouting
|
||||
}
|
||||
panic(fmt.Sprintf("Unknown hook %d does not correspond to a builtin chain", hook))
|
||||
}
|
||||
|
||||
@@ -15,11 +15,10 @@
|
||||
package netfilter
|
||||
|
||||
import (
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/iptables"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
)
|
||||
|
||||
// JumpTarget implements iptables.Target.
|
||||
// JumpTarget implements stack.Target.
|
||||
type JumpTarget struct {
|
||||
// Offset is the byte offset of the rule to jump to. It is used for
|
||||
// marshaling and unmarshaling.
|
||||
@@ -29,7 +28,7 @@ type JumpTarget struct {
|
||||
RuleNum int
|
||||
}
|
||||
|
||||
// Action implements iptables.Target.Action.
|
||||
func (jt JumpTarget) Action(tcpip.PacketBuffer) (iptables.RuleVerdict, int) {
|
||||
return iptables.RuleJump, jt.RuleNum
|
||||
// Action implements stack.Target.Action.
|
||||
func (jt JumpTarget) Action(stack.PacketBuffer) (stack.RuleVerdict, int) {
|
||||
return stack.RuleJump, jt.RuleNum
|
||||
}
|
||||
|
||||
@@ -19,9 +19,8 @@ import (
|
||||
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/binary"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/iptables"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
|
||||
@@ -40,7 +39,7 @@ func (tcpMarshaler) name() string {
|
||||
}
|
||||
|
||||
// marshal implements matchMaker.marshal.
|
||||
func (tcpMarshaler) marshal(mr iptables.Matcher) []byte {
|
||||
func (tcpMarshaler) marshal(mr stack.Matcher) []byte {
|
||||
matcher := mr.(*TCPMatcher)
|
||||
xttcp := linux.XTTCP{
|
||||
SourcePortStart: matcher.sourcePortStart,
|
||||
@@ -53,7 +52,7 @@ func (tcpMarshaler) marshal(mr iptables.Matcher) []byte {
|
||||
}
|
||||
|
||||
// unmarshal implements matchMaker.unmarshal.
|
||||
func (tcpMarshaler) unmarshal(buf []byte, filter iptables.IPHeaderFilter) (iptables.Matcher, error) {
|
||||
func (tcpMarshaler) unmarshal(buf []byte, filter stack.IPHeaderFilter) (stack.Matcher, error) {
|
||||
if len(buf) < linux.SizeOfXTTCP {
|
||||
return nil, fmt.Errorf("buf has insufficient size for TCP match: %d", len(buf))
|
||||
}
|
||||
@@ -97,7 +96,7 @@ func (*TCPMatcher) Name() string {
|
||||
}
|
||||
|
||||
// Match implements Matcher.Match.
|
||||
func (tm *TCPMatcher) Match(hook iptables.Hook, pkt tcpip.PacketBuffer, interfaceName string) (bool, bool) {
|
||||
func (tm *TCPMatcher) Match(hook stack.Hook, pkt stack.PacketBuffer, interfaceName string) (bool, bool) {
|
||||
netHeader := header.IPv4(pkt.NetworkHeader)
|
||||
|
||||
if netHeader.TransportProtocol() != header.TCPProtocolNumber {
|
||||
@@ -115,7 +114,7 @@ func (tm *TCPMatcher) Match(hook iptables.Hook, pkt tcpip.PacketBuffer, interfac
|
||||
// Now we need the transport header. However, this may not have been set
|
||||
// yet.
|
||||
// TODO(gvisor.dev/issue/170): Parsing the transport header should
|
||||
// ultimately be moved into the iptables.Check codepath as matchers are
|
||||
// ultimately be moved into the stack.Check codepath as matchers are
|
||||
// added.
|
||||
var tcpHeader header.TCP
|
||||
if pkt.TransportHeader != nil {
|
||||
|
||||
@@ -19,9 +19,8 @@ import (
|
||||
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/binary"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/iptables"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
|
||||
@@ -40,7 +39,7 @@ func (udpMarshaler) name() string {
|
||||
}
|
||||
|
||||
// marshal implements matchMaker.marshal.
|
||||
func (udpMarshaler) marshal(mr iptables.Matcher) []byte {
|
||||
func (udpMarshaler) marshal(mr stack.Matcher) []byte {
|
||||
matcher := mr.(*UDPMatcher)
|
||||
xtudp := linux.XTUDP{
|
||||
SourcePortStart: matcher.sourcePortStart,
|
||||
@@ -53,7 +52,7 @@ func (udpMarshaler) marshal(mr iptables.Matcher) []byte {
|
||||
}
|
||||
|
||||
// unmarshal implements matchMaker.unmarshal.
|
||||
func (udpMarshaler) unmarshal(buf []byte, filter iptables.IPHeaderFilter) (iptables.Matcher, error) {
|
||||
func (udpMarshaler) unmarshal(buf []byte, filter stack.IPHeaderFilter) (stack.Matcher, error) {
|
||||
if len(buf) < linux.SizeOfXTUDP {
|
||||
return nil, fmt.Errorf("buf has insufficient size for UDP match: %d", len(buf))
|
||||
}
|
||||
@@ -94,11 +93,11 @@ func (*UDPMatcher) Name() string {
|
||||
}
|
||||
|
||||
// Match implements Matcher.Match.
|
||||
func (um *UDPMatcher) Match(hook iptables.Hook, pkt tcpip.PacketBuffer, interfaceName string) (bool, bool) {
|
||||
func (um *UDPMatcher) Match(hook stack.Hook, pkt stack.PacketBuffer, interfaceName string) (bool, bool) {
|
||||
netHeader := header.IPv4(pkt.NetworkHeader)
|
||||
|
||||
// TODO(gvisor.dev/issue/170): Proto checks should ultimately be moved
|
||||
// into the iptables.Check codepath as matchers are added.
|
||||
// into the stack.Check codepath as matchers are added.
|
||||
if netHeader.TransportProtocol() != header.UDPProtocolNumber {
|
||||
return false, false
|
||||
}
|
||||
@@ -114,7 +113,7 @@ func (um *UDPMatcher) Match(hook iptables.Hook, pkt tcpip.PacketBuffer, interfac
|
||||
// Now we need the transport header. However, this may not have been set
|
||||
// yet.
|
||||
// TODO(gvisor.dev/issue/170): Parsing the transport header should
|
||||
// ultimately be moved into the iptables.Check codepath as matchers are
|
||||
// ultimately be moved into the stack.Check codepath as matchers are
|
||||
// added.
|
||||
var udpHeader header.UDP
|
||||
if pkt.TransportHeader != nil {
|
||||
|
||||
@@ -38,7 +38,6 @@ go_library(
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/buffer",
|
||||
"//pkg/tcpip/header",
|
||||
"//pkg/tcpip/iptables",
|
||||
"//pkg/tcpip/network/ipv4",
|
||||
"//pkg/tcpip/network/ipv6",
|
||||
"//pkg/tcpip/stack",
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/iptables"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
@@ -363,7 +362,7 @@ func (s *Stack) RouteTable() []inet.Route {
|
||||
}
|
||||
|
||||
// IPTables returns the stack's iptables.
|
||||
func (s *Stack) IPTables() (iptables.IPTables, error) {
|
||||
func (s *Stack) IPTables() (stack.IPTables, error) {
|
||||
return s.Stack.IPTables(), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ package(licenses = ["notice"])
|
||||
go_library(
|
||||
name = "tcpip",
|
||||
srcs = [
|
||||
"packet_buffer.go",
|
||||
"packet_buffer_state.go",
|
||||
"tcpip.go",
|
||||
"time_unsafe.go",
|
||||
"timer.go",
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
load("//tools:defs.bzl", "go_library")
|
||||
|
||||
package(licenses = ["notice"])
|
||||
|
||||
go_library(
|
||||
name = "iptables",
|
||||
srcs = [
|
||||
"iptables.go",
|
||||
"targets.go",
|
||||
"types.go",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//pkg/log",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/header",
|
||||
],
|
||||
)
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
|
||||
// PacketInfo holds all the information about an outbound packet.
|
||||
type PacketInfo struct {
|
||||
Pkt tcpip.PacketBuffer
|
||||
Pkt stack.PacketBuffer
|
||||
Proto tcpip.NetworkProtocolNumber
|
||||
GSO *stack.GSO
|
||||
Route stack.Route
|
||||
@@ -203,12 +203,12 @@ func (e *Endpoint) NumQueued() int {
|
||||
}
|
||||
|
||||
// InjectInbound injects an inbound packet.
|
||||
func (e *Endpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) {
|
||||
func (e *Endpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBuffer) {
|
||||
e.InjectLinkAddr(protocol, "", pkt)
|
||||
}
|
||||
|
||||
// InjectLinkAddr injects an inbound packet with a remote link address.
|
||||
func (e *Endpoint) InjectLinkAddr(protocol tcpip.NetworkProtocolNumber, remote tcpip.LinkAddress, pkt tcpip.PacketBuffer) {
|
||||
func (e *Endpoint) InjectLinkAddr(protocol tcpip.NetworkProtocolNumber, remote tcpip.LinkAddress, pkt stack.PacketBuffer) {
|
||||
e.dispatcher.DeliverNetworkPacket(e, remote, "" /* local */, protocol, pkt)
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ func (e *Endpoint) LinkAddress() tcpip.LinkAddress {
|
||||
}
|
||||
|
||||
// WritePacket stores outbound packets into the channel.
|
||||
func (e *Endpoint) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) *tcpip.Error {
|
||||
func (e *Endpoint) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBuffer) *tcpip.Error {
|
||||
// Clone r then release its resource so we only get the relevant fields from
|
||||
// stack.Route without holding a reference to a NIC's endpoint.
|
||||
route := r.Clone()
|
||||
@@ -269,7 +269,7 @@ func (e *Endpoint) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.Ne
|
||||
}
|
||||
|
||||
// WritePackets stores outbound packets into the channel.
|
||||
func (e *Endpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts []tcpip.PacketBuffer, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
|
||||
func (e *Endpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts []stack.PacketBuffer, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
|
||||
// Clone r then release its resource so we only get the relevant fields from
|
||||
// stack.Route without holding a reference to a NIC's endpoint.
|
||||
route := r.Clone()
|
||||
@@ -280,7 +280,7 @@ func (e *Endpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts []tcpip.Pac
|
||||
off := pkt.DataOffset
|
||||
size := pkt.DataSize
|
||||
p := PacketInfo{
|
||||
Pkt: tcpip.PacketBuffer{
|
||||
Pkt: stack.PacketBuffer{
|
||||
Header: pkt.Header,
|
||||
Data: buffer.NewViewFromBytes(payloadView[off : off+size]).ToVectorisedView(),
|
||||
},
|
||||
@@ -301,7 +301,7 @@ func (e *Endpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts []tcpip.Pac
|
||||
// WriteRawPacket implements stack.LinkEndpoint.WriteRawPacket.
|
||||
func (e *Endpoint) WriteRawPacket(vv buffer.VectorisedView) *tcpip.Error {
|
||||
p := PacketInfo{
|
||||
Pkt: tcpip.PacketBuffer{Data: vv},
|
||||
Pkt: stack.PacketBuffer{Data: vv},
|
||||
Proto: 0,
|
||||
GSO: nil,
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ const (
|
||||
|
||||
// WritePacket writes outbound packets to the file descriptor. If it is not
|
||||
// currently writable, the packet is dropped.
|
||||
func (e *endpoint) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) *tcpip.Error {
|
||||
func (e *endpoint) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBuffer) *tcpip.Error {
|
||||
if e.hdrSize > 0 {
|
||||
// Add ethernet header if needed.
|
||||
eth := header.Ethernet(pkt.Header.Prepend(header.EthernetMinimumSize))
|
||||
@@ -440,7 +440,7 @@ func (e *endpoint) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.Ne
|
||||
|
||||
// WritePackets writes outbound packets to the file descriptor. If it is not
|
||||
// currently writable, the packet is dropped.
|
||||
func (e *endpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts []tcpip.PacketBuffer, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
|
||||
func (e *endpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts []stack.PacketBuffer, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
|
||||
var ethHdrBuf []byte
|
||||
// hdr + data
|
||||
iovLen := 2
|
||||
@@ -610,7 +610,7 @@ func (e *InjectableEndpoint) Attach(dispatcher stack.NetworkDispatcher) {
|
||||
}
|
||||
|
||||
// InjectInbound injects an inbound packet.
|
||||
func (e *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) {
|
||||
func (e *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBuffer) {
|
||||
e.dispatcher.DeliverNetworkPacket(e, "" /* remote */, "" /* local */, protocol, pkt)
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ const (
|
||||
type packetInfo struct {
|
||||
raddr tcpip.LinkAddress
|
||||
proto tcpip.NetworkProtocolNumber
|
||||
contents tcpip.PacketBuffer
|
||||
contents stack.PacketBuffer
|
||||
}
|
||||
|
||||
type context struct {
|
||||
@@ -92,7 +92,7 @@ func (c *context) cleanup() {
|
||||
syscall.Close(c.fds[1])
|
||||
}
|
||||
|
||||
func (c *context) DeliverNetworkPacket(linkEP stack.LinkEndpoint, remote tcpip.LinkAddress, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) {
|
||||
func (c *context) DeliverNetworkPacket(linkEP stack.LinkEndpoint, remote tcpip.LinkAddress, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBuffer) {
|
||||
c.ch <- packetInfo{remote, protocol, pkt}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ func testWritePacket(t *testing.T, plen int, eth bool, gsoMaxSize uint32) {
|
||||
L3HdrLen: header.IPv4MaximumHeaderSize,
|
||||
}
|
||||
}
|
||||
if err := c.ep.WritePacket(r, gso, proto, tcpip.PacketBuffer{
|
||||
if err := c.ep.WritePacket(r, gso, proto, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: payload.ToVectorisedView(),
|
||||
}); err != nil {
|
||||
@@ -261,7 +261,7 @@ func TestPreserveSrcAddress(t *testing.T) {
|
||||
// WritePacket panics given a prependable with anything less than
|
||||
// the minimum size of the ethernet header.
|
||||
hdr := buffer.NewPrependable(header.EthernetMinimumSize)
|
||||
if err := c.ep.WritePacket(r, nil /* gso */, proto, tcpip.PacketBuffer{
|
||||
if err := c.ep.WritePacket(r, nil /* gso */, proto, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buffer.VectorisedView{},
|
||||
}); err != nil {
|
||||
@@ -324,7 +324,7 @@ func TestDeliverPacket(t *testing.T) {
|
||||
want := packetInfo{
|
||||
raddr: raddr,
|
||||
proto: proto,
|
||||
contents: tcpip.PacketBuffer{
|
||||
contents: stack.PacketBuffer{
|
||||
Data: buffer.View(b).ToVectorisedView(),
|
||||
LinkHeader: buffer.View(hdr),
|
||||
},
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/link/rawfile"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -190,7 +191,7 @@ func (d *packetMMapDispatcher) dispatch() (bool, *tcpip.Error) {
|
||||
}
|
||||
|
||||
pkt = pkt[d.e.hdrSize:]
|
||||
d.e.dispatcher.DeliverNetworkPacket(d.e, remote, local, p, tcpip.PacketBuffer{
|
||||
d.e.dispatcher.DeliverNetworkPacket(d.e, remote, local, p, stack.PacketBuffer{
|
||||
Data: buffer.View(pkt).ToVectorisedView(),
|
||||
LinkHeader: buffer.View(eth),
|
||||
})
|
||||
|
||||
@@ -139,7 +139,7 @@ func (d *readVDispatcher) dispatch() (bool, *tcpip.Error) {
|
||||
}
|
||||
|
||||
used := d.capViews(n, BufConfig)
|
||||
pkt := tcpip.PacketBuffer{
|
||||
pkt := stack.PacketBuffer{
|
||||
Data: buffer.NewVectorisedView(n, append([]buffer.View(nil), d.views[:used]...)),
|
||||
LinkHeader: buffer.View(eth),
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func (d *recvMMsgDispatcher) dispatch() (bool, *tcpip.Error) {
|
||||
}
|
||||
|
||||
used := d.capViews(k, int(n), BufConfig)
|
||||
pkt := tcpip.PacketBuffer{
|
||||
pkt := stack.PacketBuffer{
|
||||
Data: buffer.NewVectorisedView(int(n), append([]buffer.View(nil), d.views[k][:used]...)),
|
||||
LinkHeader: buffer.View(eth),
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (*endpoint) Wait() {}
|
||||
|
||||
// WritePacket implements stack.LinkEndpoint.WritePacket. It delivers outbound
|
||||
// packets to the network-layer dispatcher.
|
||||
func (e *endpoint) WritePacket(_ *stack.Route, _ *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) *tcpip.Error {
|
||||
func (e *endpoint) WritePacket(_ *stack.Route, _ *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBuffer) *tcpip.Error {
|
||||
views := make([]buffer.View, 1, 1+len(pkt.Data.Views()))
|
||||
views[0] = pkt.Header.View()
|
||||
views = append(views, pkt.Data.Views()...)
|
||||
@@ -84,7 +84,7 @@ func (e *endpoint) WritePacket(_ *stack.Route, _ *stack.GSO, protocol tcpip.Netw
|
||||
// Because we're immediately turning around and writing the packet back
|
||||
// to the rx path, we intentionally don't preserve the remote and local
|
||||
// link addresses from the stack.Route we're passed.
|
||||
e.dispatcher.DeliverNetworkPacket(e, "" /* remote */, "" /* local */, protocol, tcpip.PacketBuffer{
|
||||
e.dispatcher.DeliverNetworkPacket(e, "" /* remote */, "" /* local */, protocol, stack.PacketBuffer{
|
||||
Data: buffer.NewVectorisedView(len(views[0])+pkt.Data.Size(), views),
|
||||
})
|
||||
|
||||
@@ -92,7 +92,7 @@ func (e *endpoint) WritePacket(_ *stack.Route, _ *stack.GSO, protocol tcpip.Netw
|
||||
}
|
||||
|
||||
// WritePackets implements stack.LinkEndpoint.WritePackets.
|
||||
func (e *endpoint) WritePackets(*stack.Route, *stack.GSO, []tcpip.PacketBuffer, tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
|
||||
func (e *endpoint) WritePackets(*stack.Route, *stack.GSO, []stack.PacketBuffer, tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (e *endpoint) WriteRawPacket(vv buffer.VectorisedView) *tcpip.Error {
|
||||
// There should be an ethernet header at the beginning of vv.
|
||||
linkHeader := header.Ethernet(vv.First()[:header.EthernetMinimumSize])
|
||||
vv.TrimFront(len(linkHeader))
|
||||
e.dispatcher.DeliverNetworkPacket(e, "" /* remote */, "" /* local */, linkHeader.Type(), tcpip.PacketBuffer{
|
||||
e.dispatcher.DeliverNetworkPacket(e, "" /* remote */, "" /* local */, linkHeader.Type(), stack.PacketBuffer{
|
||||
Data: vv,
|
||||
LinkHeader: buffer.View(linkHeader),
|
||||
})
|
||||
|
||||
@@ -80,14 +80,14 @@ func (m *InjectableEndpoint) IsAttached() bool {
|
||||
}
|
||||
|
||||
// InjectInbound implements stack.InjectableLinkEndpoint.
|
||||
func (m *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) {
|
||||
func (m *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBuffer) {
|
||||
m.dispatcher.DeliverNetworkPacket(m, "" /* remote */, "" /* local */, protocol, pkt)
|
||||
}
|
||||
|
||||
// WritePackets writes outbound packets to the appropriate
|
||||
// LinkInjectableEndpoint based on the RemoteAddress. HandleLocal only works if
|
||||
// r.RemoteAddress has a route registered in this endpoint.
|
||||
func (m *InjectableEndpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts []tcpip.PacketBuffer, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
|
||||
func (m *InjectableEndpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts []stack.PacketBuffer, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
|
||||
endpoint, ok := m.routes[r.RemoteAddress]
|
||||
if !ok {
|
||||
return 0, tcpip.ErrNoRoute
|
||||
@@ -98,7 +98,7 @@ func (m *InjectableEndpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts [
|
||||
// WritePacket writes outbound packets to the appropriate LinkInjectableEndpoint
|
||||
// based on the RemoteAddress. HandleLocal only works if r.RemoteAddress has a
|
||||
// route registered in this endpoint.
|
||||
func (m *InjectableEndpoint) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) *tcpip.Error {
|
||||
func (m *InjectableEndpoint) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBuffer) *tcpip.Error {
|
||||
if endpoint, ok := m.routes[r.RemoteAddress]; ok {
|
||||
return endpoint.WritePacket(r, gso, protocol, pkt)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestInjectableEndpointDispatch(t *testing.T) {
|
||||
hdr.Prepend(1)[0] = 0xFA
|
||||
packetRoute := stack.Route{RemoteAddress: dstIP}
|
||||
|
||||
endpoint.WritePacket(&packetRoute, nil /* gso */, ipv4.ProtocolNumber, tcpip.PacketBuffer{
|
||||
endpoint.WritePacket(&packetRoute, nil /* gso */, ipv4.ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buffer.NewViewFromBytes([]byte{0xFB}).ToVectorisedView(),
|
||||
})
|
||||
@@ -70,7 +70,7 @@ func TestInjectableEndpointDispatchHdrOnly(t *testing.T) {
|
||||
hdr := buffer.NewPrependable(1)
|
||||
hdr.Prepend(1)[0] = 0xFA
|
||||
packetRoute := stack.Route{RemoteAddress: dstIP}
|
||||
endpoint.WritePacket(&packetRoute, nil /* gso */, ipv4.ProtocolNumber, tcpip.PacketBuffer{
|
||||
endpoint.WritePacket(&packetRoute, nil /* gso */, ipv4.ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buffer.NewView(0).ToVectorisedView(),
|
||||
})
|
||||
|
||||
@@ -185,7 +185,7 @@ func (e *endpoint) LinkAddress() tcpip.LinkAddress {
|
||||
|
||||
// WritePacket writes outbound packets to the file descriptor. If it is not
|
||||
// currently writable, the packet is dropped.
|
||||
func (e *endpoint) WritePacket(r *stack.Route, _ *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) *tcpip.Error {
|
||||
func (e *endpoint) WritePacket(r *stack.Route, _ *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBuffer) *tcpip.Error {
|
||||
// Add the ethernet header here.
|
||||
eth := header.Ethernet(pkt.Header.Prepend(header.EthernetMinimumSize))
|
||||
pkt.LinkHeader = buffer.View(eth)
|
||||
@@ -214,7 +214,7 @@ func (e *endpoint) WritePacket(r *stack.Route, _ *stack.GSO, protocol tcpip.Netw
|
||||
}
|
||||
|
||||
// WritePackets implements stack.LinkEndpoint.WritePackets.
|
||||
func (e *endpoint) WritePackets(r *stack.Route, _ *stack.GSO, pkts []tcpip.PacketBuffer, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
|
||||
func (e *endpoint) WritePackets(r *stack.Route, _ *stack.GSO, pkts []stack.PacketBuffer, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ func (e *endpoint) dispatchLoop(d stack.NetworkDispatcher) {
|
||||
|
||||
// Send packet up the stack.
|
||||
eth := header.Ethernet(b[:header.EthernetMinimumSize])
|
||||
d.DeliverNetworkPacket(e, eth.SourceAddress(), eth.DestinationAddress(), eth.Type(), tcpip.PacketBuffer{
|
||||
d.DeliverNetworkPacket(e, eth.SourceAddress(), eth.DestinationAddress(), eth.Type(), stack.PacketBuffer{
|
||||
Data: buffer.View(b[header.EthernetMinimumSize:]).ToVectorisedView(),
|
||||
LinkHeader: buffer.View(eth),
|
||||
})
|
||||
|
||||
@@ -131,7 +131,7 @@ func newTestContext(t *testing.T, mtu, bufferSize uint32, addr tcpip.LinkAddress
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *testContext) DeliverNetworkPacket(_ stack.LinkEndpoint, remoteLinkAddr, localLinkAddr tcpip.LinkAddress, proto tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) {
|
||||
func (c *testContext) DeliverNetworkPacket(_ stack.LinkEndpoint, remoteLinkAddr, localLinkAddr tcpip.LinkAddress, proto tcpip.NetworkProtocolNumber, pkt stack.PacketBuffer) {
|
||||
c.mu.Lock()
|
||||
c.packets = append(c.packets, packetInfo{
|
||||
addr: remoteLinkAddr,
|
||||
@@ -273,7 +273,7 @@ func TestSimpleSend(t *testing.T) {
|
||||
randomFill(buf)
|
||||
|
||||
proto := tcpip.NetworkProtocolNumber(rand.Intn(0x10000))
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, proto, tcpip.PacketBuffer{
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, proto, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buf.ToVectorisedView(),
|
||||
}); err != nil {
|
||||
@@ -345,7 +345,7 @@ func TestPreserveSrcAddressInSend(t *testing.T) {
|
||||
hdr := buffer.NewPrependable(header.EthernetMinimumSize)
|
||||
|
||||
proto := tcpip.NetworkProtocolNumber(rand.Intn(0x10000))
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, proto, tcpip.PacketBuffer{
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, proto, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
}); err != nil {
|
||||
t.Fatalf("WritePacket failed: %v", err)
|
||||
@@ -401,7 +401,7 @@ func TestFillTxQueue(t *testing.T) {
|
||||
for i := queuePipeSize / 40; i > 0; i-- {
|
||||
hdr := buffer.NewPrependable(int(c.ep.MaxHeaderLength()))
|
||||
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, tcpip.PacketBuffer{
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buf.ToVectorisedView(),
|
||||
}); err != nil {
|
||||
@@ -419,7 +419,7 @@ func TestFillTxQueue(t *testing.T) {
|
||||
|
||||
// Next attempt to write must fail.
|
||||
hdr := buffer.NewPrependable(int(c.ep.MaxHeaderLength()))
|
||||
if want, err := tcpip.ErrWouldBlock, c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, tcpip.PacketBuffer{
|
||||
if want, err := tcpip.ErrWouldBlock, c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buf.ToVectorisedView(),
|
||||
}); err != want {
|
||||
@@ -447,7 +447,7 @@ func TestFillTxQueueAfterBadCompletion(t *testing.T) {
|
||||
// Send two packets so that the id slice has at least two slots.
|
||||
for i := 2; i > 0; i-- {
|
||||
hdr := buffer.NewPrependable(int(c.ep.MaxHeaderLength()))
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, tcpip.PacketBuffer{
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buf.ToVectorisedView(),
|
||||
}); err != nil {
|
||||
@@ -470,7 +470,7 @@ func TestFillTxQueueAfterBadCompletion(t *testing.T) {
|
||||
ids := make(map[uint64]struct{})
|
||||
for i := queuePipeSize / 40; i > 0; i-- {
|
||||
hdr := buffer.NewPrependable(int(c.ep.MaxHeaderLength()))
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, tcpip.PacketBuffer{
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buf.ToVectorisedView(),
|
||||
}); err != nil {
|
||||
@@ -488,7 +488,7 @@ func TestFillTxQueueAfterBadCompletion(t *testing.T) {
|
||||
|
||||
// Next attempt to write must fail.
|
||||
hdr := buffer.NewPrependable(int(c.ep.MaxHeaderLength()))
|
||||
if want, err := tcpip.ErrWouldBlock, c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, tcpip.PacketBuffer{
|
||||
if want, err := tcpip.ErrWouldBlock, c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buf.ToVectorisedView(),
|
||||
}); err != want {
|
||||
@@ -514,7 +514,7 @@ func TestFillTxMemory(t *testing.T) {
|
||||
ids := make(map[uint64]struct{})
|
||||
for i := queueDataSize / bufferSize; i > 0; i-- {
|
||||
hdr := buffer.NewPrependable(int(c.ep.MaxHeaderLength()))
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, tcpip.PacketBuffer{
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buf.ToVectorisedView(),
|
||||
}); err != nil {
|
||||
@@ -533,7 +533,7 @@ func TestFillTxMemory(t *testing.T) {
|
||||
|
||||
// Next attempt to write must fail.
|
||||
hdr := buffer.NewPrependable(int(c.ep.MaxHeaderLength()))
|
||||
err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, tcpip.PacketBuffer{
|
||||
err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buf.ToVectorisedView(),
|
||||
})
|
||||
@@ -561,7 +561,7 @@ func TestFillTxMemoryWithMultiBuffer(t *testing.T) {
|
||||
// until there is only one buffer left.
|
||||
for i := queueDataSize/bufferSize - 1; i > 0; i-- {
|
||||
hdr := buffer.NewPrependable(int(c.ep.MaxHeaderLength()))
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, tcpip.PacketBuffer{
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buf.ToVectorisedView(),
|
||||
}); err != nil {
|
||||
@@ -577,7 +577,7 @@ func TestFillTxMemoryWithMultiBuffer(t *testing.T) {
|
||||
{
|
||||
hdr := buffer.NewPrependable(int(c.ep.MaxHeaderLength()))
|
||||
uu := buffer.NewView(bufferSize).ToVectorisedView()
|
||||
if want, err := tcpip.ErrWouldBlock, c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, tcpip.PacketBuffer{
|
||||
if want, err := tcpip.ErrWouldBlock, c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: uu,
|
||||
}); err != want {
|
||||
@@ -588,7 +588,7 @@ func TestFillTxMemoryWithMultiBuffer(t *testing.T) {
|
||||
// Attempt to write the one-buffer packet again. It must succeed.
|
||||
{
|
||||
hdr := buffer.NewPrependable(int(c.ep.MaxHeaderLength()))
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, tcpip.PacketBuffer{
|
||||
if err := c.ep.WritePacket(&r, nil /* gso */, header.IPv4ProtocolNumber, stack.PacketBuffer{
|
||||
Header: hdr,
|
||||
Data: buf.ToVectorisedView(),
|
||||
}); err != nil {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user