diff options
Diffstat (limited to 'packet/validate.go')
-rw-r--r-- | packet/validate.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/packet/validate.go b/packet/validate.go new file mode 100644 index 00000000..e3ddf58b --- /dev/null +++ b/packet/validate.go @@ -0,0 +1,39 @@ +package bgp + +import ( + "strconv" +) + +// validator for PathAttribute +func ValidateFlags(t BGPAttrType, flags uint8) (bool, string) { + + /* + * RFC 4271 P.17 For well-known attributes, the Transitive bit MUST be set to 1. + */ + if flags&BGP_ATTR_FLAG_OPTIONAL == 0 && flags&BGP_ATTR_FLAG_TRANSITIVE == 0 { + eMsg := "well-known attribute must have transitive flag 1" + return false, eMsg + } + /* + * RFC 4271 P.17 For well-known attributes and for optional non-transitive attributes, + * the Partial bit MUST be set to 0. + */ + if flags&BGP_ATTR_FLAG_OPTIONAL == 0 && flags&BGP_ATTR_FLAG_PARTIAL != 0 { + eMsg := "well-known attribute must have partial bit 0" + return false, eMsg + } + if flags&BGP_ATTR_FLAG_OPTIONAL != 0 && flags&BGP_ATTR_FLAG_TRANSITIVE == 0 && flags&BGP_ATTR_FLAG_PARTIAL != 0 { + eMsg := "optional non-transitive attribute must have partial bit 0" + return false, eMsg + } + + // check flags are correct + + if f, ok := pathAttrFlags[t]; ok { + if f != flags { + eMsg := "flags are invalid. attribtue type : " + strconv.Itoa(int(t)) + return false, eMsg + } + } + return true, "" +} |