diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-01-13 15:11:57 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-16 18:17:40 +0900 |
commit | c65fe8515e64ee4c61331fd266d4fe51a10b45ff (patch) | |
tree | 57f4d9084149d51a8fdea4ae3b9eac89df3d4756 | |
parent | f94bfa02a48b597f1636bc3671247e050d2c7723 (diff) |
add packet validator
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-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, "" +} |