mirror of
https://github.com/impact-eintr/netstack.git
synced 2025-11-02 18:14:02 +08:00
fix bug: 分片机制应该使用vv.ToViews()获取全部的数据而非First()的第一片区
This commit is contained in:
@@ -155,7 +155,7 @@ func (conn *UdpConn) Read(rcv []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
return 0, fmt.Errorf("%s", err.String())
|
return 0, fmt.Errorf("%s", err.String())
|
||||||
}
|
}
|
||||||
rcv = append(rcv[:0], buf...)
|
rcv = append(rcv[:0], buf[:cap(rcv)]...)
|
||||||
return len(rcv), nil
|
return len(rcv), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func main() {
|
|||||||
log.Println("TEST")
|
log.Println("TEST")
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
send := []byte("hello" + string(i))
|
send := make([]byte, 2048)
|
||||||
if _, err := conn.Write(send); err != nil {
|
if _, err := conn.Write(send); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ func New(opts *Options) tcpip.LinkEndpointID {
|
|||||||
iovecs: make([]syscall.Iovec, len(BufConfig)),
|
iovecs: make([]syscall.Iovec, len(BufConfig)),
|
||||||
handleLocal: opts.HandleLocal,
|
handleLocal: opts.HandleLocal,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全局注册链路层设备
|
// 全局注册链路层设备
|
||||||
return stack.RegisterLinkEndpoint(e)
|
return stack.RegisterLinkEndpoint(e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ func (e *endpoint) WritePacket(r *stack.Route, hdr buffer.Prependable, payload b
|
|||||||
// 收到ip包的处理
|
// 收到ip包的处理
|
||||||
func (e *endpoint) HandlePacket(r *stack.Route, vv buffer.VectorisedView) {
|
func (e *endpoint) HandlePacket(r *stack.Route, vv buffer.VectorisedView) {
|
||||||
// 得到ip报文
|
// 得到ip报文
|
||||||
h := header.IPv4(vv.First())
|
h := header.IPv4(vv.ToView())
|
||||||
// 检查报文是否有效
|
// 检查报文是否有效
|
||||||
if !h.IsValid(vv.Size()) {
|
if !h.IsValid(vv.Size()) {
|
||||||
return
|
return
|
||||||
@@ -132,6 +132,7 @@ func (e *endpoint) HandlePacket(r *stack.Route, vv buffer.VectorisedView) {
|
|||||||
tlen := int(h.TotalLength())
|
tlen := int(h.TotalLength())
|
||||||
vv.TrimFront(hlen)
|
vv.TrimFront(hlen)
|
||||||
vv.CapLength(tlen - hlen)
|
vv.CapLength(tlen - hlen)
|
||||||
|
log.Println(hlen, tlen)
|
||||||
|
|
||||||
// 报文重组
|
// 报文重组
|
||||||
more := (h.Flags() & header.IPv4FlagMoreFragments) != 0
|
more := (h.Flags() & header.IPv4FlagMoreFragments) != 0
|
||||||
|
|||||||
@@ -436,7 +436,7 @@ func (e *endpoint) GetSockOpt(opt interface{}) *tcpip.Error {
|
|||||||
// 但是队列存数据量是有限制的,这个限制叫接收缓存大小,当接收队列中的数据总和超过这个缓存,那么接下来的这些报文将会被直接丢包。
|
// 但是队列存数据量是有限制的,这个限制叫接收缓存大小,当接收队列中的数据总和超过这个缓存,那么接下来的这些报文将会被直接丢包。
|
||||||
func (e *endpoint) HandlePacket(r *stack.Route, id stack.TransportEndpointID, vv buffer.VectorisedView) {
|
func (e *endpoint) HandlePacket(r *stack.Route, id stack.TransportEndpointID, vv buffer.VectorisedView) {
|
||||||
// Get the header then trim it from the view.
|
// Get the header then trim it from the view.
|
||||||
hdr := header.UDP(vv.First())
|
hdr := header.UDP(vv.ToView())
|
||||||
if int(hdr.Length()) > vv.Size() {
|
if int(hdr.Length()) > vv.Size() {
|
||||||
// Malformed packet.
|
// Malformed packet.
|
||||||
// 错误报文
|
// 错误报文
|
||||||
|
|||||||
Reference in New Issue
Block a user