mirror of
https://github.com/soypat/lneto.git
synced 2026-08-16 12:53:26 +00:00
round most of stack example
This commit is contained in:
+21
-9
@@ -17,11 +17,14 @@ var (
|
||||
|
||||
errBadIPVersion = errors.New("bad IP version field")
|
||||
errEvilPacket = errors.New("evil packet")
|
||||
errZeroDstPort = errors.New("TCP zero destination port")
|
||||
errZeroSrcPort = errors.New("TCP zero source port")
|
||||
)
|
||||
|
||||
type Validator struct {
|
||||
checkEvil bool
|
||||
accum []error
|
||||
checkEvil bool
|
||||
allowMultiErrs bool
|
||||
accum []error
|
||||
}
|
||||
|
||||
func (v *Validator) ResetErr() {
|
||||
@@ -38,6 +41,9 @@ func (v *Validator) Err() error {
|
||||
}
|
||||
|
||||
func (v *Validator) gotErr(err error) {
|
||||
if len(v.accum) != 0 && !v.allowMultiErrs {
|
||||
return
|
||||
}
|
||||
v.accum = append(v.accum, err)
|
||||
}
|
||||
|
||||
@@ -80,7 +86,9 @@ func (ifrm IPv4Frame) ValidateSize(v *Validator) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ifrm IPv4Frame) ValidateFields(v *Validator) {
|
||||
// ValidateExceptCRC checks for invalid frame values but does not check CRC.
|
||||
func (ifrm IPv4Frame) ValidateExceptCRC(v *Validator) {
|
||||
ifrm.ValidateSize(v)
|
||||
flags := ifrm.Flags()
|
||||
if ifrm.version() != 4 {
|
||||
v.gotErr(errBadIPVersion)
|
||||
@@ -90,12 +98,6 @@ func (ifrm IPv4Frame) ValidateFields(v *Validator) {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate checks for invalid frame values.
|
||||
func (ifrm IPv4Frame) Validate(v *Validator) {
|
||||
ifrm.ValidateSize(v)
|
||||
ifrm.ValidateFields(v)
|
||||
}
|
||||
|
||||
// ValidateSize checks the frame's size fields and compares with the actual buffer
|
||||
// the frame. It returns a non-nil error on finding an inconsistency.
|
||||
func (i6frm IPv6Frame) ValidateSize(v *Validator) {
|
||||
@@ -117,6 +119,16 @@ func (tfrm TCPFrame) ValidateSize(v *Validator) {
|
||||
}
|
||||
}
|
||||
|
||||
func (tfrm TCPFrame) ValidateExceptCRC(v *Validator) {
|
||||
tfrm.ValidateSize(v)
|
||||
if tfrm.DestinationPort() == 0 {
|
||||
v.gotErr(errZeroDstPort)
|
||||
}
|
||||
if tfrm.SourcePort() == 0 {
|
||||
v.gotErr(errZeroSrcPort)
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateSize checks the frame's size fields and compares with the actual buffer
|
||||
// the frame. It returns a non-nil error on finding an inconsistency.
|
||||
func (ufrm UDPFrame) ValidateSize(v *Validator) {
|
||||
|
||||
Reference in New Issue
Block a user