Committed by
Gerrit Code Review
[ONOS-2939] Let sdn-ip also can parse bird's bgp OPEN message
RFC5492 allows multiple Capability triples per Optional Parameter. But our code only support parsing 1 Capability triple per Optional Parameter. It works with Quagga, but failed parsing bird OPEN message. This patch adds support for multiple Capability triples per Optional Parameter. Change-Id: Iae6295d608e44676a44ef6a0ae1868d8dcd7648d
Showing
1 changed file
with
16 additions
and
6 deletions
... | @@ -309,16 +309,25 @@ final class BgpOpen { | ... | @@ -309,16 +309,25 @@ final class BgpOpen { |
309 | case BgpConstants.Open.Capabilities.TYPE: | 309 | case BgpConstants.Open.Capabilities.TYPE: |
310 | // Optional Parameter Type: Capabilities | 310 | // Optional Parameter Type: Capabilities |
311 | if (paramLen < BgpConstants.Open.Capabilities.MIN_LENGTH) { | 311 | if (paramLen < BgpConstants.Open.Capabilities.MIN_LENGTH) { |
312 | - // ERROR: Malformed Capability | 312 | + // ERROR: Malformed Param Type |
313 | - String errorMsg = "Malformed Capability Type " + paramType; | 313 | + String errorMsg = "Malformed Capabilities Optional " |
314 | + + "Parameter Type " + paramType; | ||
315 | + throw new BgpMessage.BgpParseException(errorMsg); | ||
316 | + } | ||
317 | + int paramEnd = message.readerIndex() + paramLen; | ||
318 | + // Parse Capabilities | ||
319 | + while (message.readerIndex() < paramEnd) { | ||
320 | + if (paramEnd - message.readerIndex() < | ||
321 | + BgpConstants.Open.Capabilities.MIN_LENGTH) { | ||
322 | + String errorMsg = "Malformed Capabilities"; | ||
314 | throw new BgpMessage.BgpParseException(errorMsg); | 323 | throw new BgpMessage.BgpParseException(errorMsg); |
315 | } | 324 | } |
316 | - int capabEnd = message.readerIndex() + paramLen; | ||
317 | int capabCode = message.readUnsignedByte(); | 325 | int capabCode = message.readUnsignedByte(); |
318 | int capabLen = message.readUnsignedByte(); | 326 | int capabLen = message.readUnsignedByte(); |
319 | - if (message.readerIndex() + capabLen > capabEnd) { | 327 | + if (message.readerIndex() + capabLen > paramEnd) { |
320 | // ERROR: Malformed Capability | 328 | // ERROR: Malformed Capability |
321 | - String errorMsg = "Malformed Capability Type " + paramType; | 329 | + String errorMsg = "Malformed Capability instance with " |
330 | + + "code " + capabCode; | ||
322 | throw new BgpMessage.BgpParseException(errorMsg); | 331 | throw new BgpMessage.BgpParseException(errorMsg); |
323 | } | 332 | } |
324 | 333 | ||
... | @@ -395,8 +404,9 @@ final class BgpOpen { | ... | @@ -395,8 +404,9 @@ final class BgpOpen { |
395 | break; | 404 | break; |
396 | } | 405 | } |
397 | 406 | ||
398 | - break; | ||
399 | 407 | ||
408 | + } | ||
409 | + break; | ||
400 | default: | 410 | default: |
401 | // Unknown Parameter Type: ignore it | 411 | // Unknown Parameter Type: ignore it |
402 | log.debug("BGP RX OPEN Parameter Type = {} Length = {}", | 412 | log.debug("BGP RX OPEN Parameter Type = {} Length = {}", | ... | ... |
-
Please register or login to post a comment