if (isMultiPathSupported) {
withdrawnRoutesBuilder.setPathId(PathIdUtil.readPathId(withdrawnRoutesBuffer));
}
- withdrawnRoutesBuilder.setPrefix(Ipv4Util.prefixForByteBuf(withdrawnRoutesBuffer));
+ withdrawnRoutesBuilder.setPrefix(readPrefix(withdrawnRoutesBuffer, errorHandling, "Withdrawn Routes"));
withdrawnRoutes.add(withdrawnRoutesBuilder.build());
}
withdrawnRoutesBuffer.release();
builder.setWithdrawnRoutes(withdrawnRoutes);
}
final int totalPathAttrLength = buffer.readUnsignedShort();
-
if (withdrawnRoutesLength == 0 && totalPathAttrLength == 0) {
return builder.build();
}
+
Optional<BGPTreatAsWithdrawException> withdrawCauseOpt;
if (totalPathAttrLength > 0) {
final ParsedAttributes attributes = parseAttributes(buffer, totalPathAttrLength, constraint);
} else {
withdrawCauseOpt = Optional.empty();
}
+
final List<Nlri> nlri = new ArrayList<>();
while (buffer.isReadable()) {
final NlriBuilder nlriBuilder = new NlriBuilder();
if (isMultiPathSupported) {
nlriBuilder.setPathId(PathIdUtil.readPathId(buffer));
}
- nlriBuilder.setPrefix(Ipv4Util.prefixForByteBuf(buffer));
+ nlriBuilder.setPrefix(readPrefix(buffer, errorHandling, "NLRI"));
nlri.add(nlriBuilder.build());
}
if (!nlri.isEmpty()) {
}
}
+ private static Ipv4Prefix readPrefix(final ByteBuf buf, final RevisedErrorHandling errorHandling,
+ final String fieldName) throws BGPDocumentedException {
+ final int prefixLength = buf.readUnsignedByte();
+ if (errorHandling != RevisedErrorHandling.NONE) {
+ // https://tools.ietf.org/html/rfc7606#section-5.3
+ if (prefixLength > 32) {
+ throw new BGPDocumentedException(fieldName + " length " + prefixLength + " exceeds 32 bytes",
+ BGPError.ATTR_LENGTH_ERROR);
+ }
+ if (prefixLength > buf.readableBytes() * 8) {
+ throw new BGPDocumentedException(fieldName + " length " + prefixLength
+ + " exceeds unconsumed field space", BGPError.ATTR_LENGTH_ERROR);
+ }
+ }
+
+ return Ipv4Util.prefixForByteBuf(buf, prefixLength);
+ }
+
/**
* Check for presence of well known mandatory path attributes ORIGIN, AS_PATH and NEXT_HOP in Update message.
*