Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgpd: Some BGP-LS adjustments #14536

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1521,8 +1521,8 @@ bgp_attr_malformed(struct bgp_attr_parser_args *args, uint8_t subcode,
case BGP_ATTR_PMSI_TUNNEL:
case BGP_ATTR_ENCAP:
case BGP_ATTR_OTC:
return BGP_ATTR_PARSE_WITHDRAW;
case BGP_ATTR_LINK_STATE:
return BGP_ATTR_PARSE_WITHDRAW;
case BGP_ATTR_MP_REACH_NLRI:
case BGP_ATTR_MP_UNREACH_NLRI:
bgp_notify_send_with_data(peer->connection,
Expand Down Expand Up @@ -3417,6 +3417,14 @@ bgp_attr_linkstate(struct bgp_attr_parser_args *args)
if (STREAM_READABLE(s) == 0)
return BGP_ATTR_PARSE_PROCEED;

/* Length check. */
if (STREAM_READABLE(s) < length) {
flog_err(EC_BGP_ATTR_LEN,
"BGP-LS attribute length is too big [%u]", length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}

attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LINK_STATE);

bgp_attr_ls = XCALLOC(MTYPE_BGP_ATTR_LS, sizeof(struct bgp_attr_ls));
Expand Down Expand Up @@ -4982,10 +4990,21 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
}

/* BGP Link-State */
if (attr->link_state) {
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL);
if (attr->link_state &&
attr->link_state->length < peer->max_packet_size) {
uint8_t flags = BGP_ATTR_FLAG_OPTIONAL;

if (attr->link_state->length > 255)
SET_FLAG(flags, BGP_ATTR_FLAG_EXTLEN);

stream_putc(s, flags);
stream_putc(s, BGP_ATTR_LINK_STATE);
stream_putc(s, attr->link_state->length);

if (CHECK_FLAG(flags, BGP_ATTR_FLAG_EXTLEN))
stream_putw(s, attr->link_state->length);
else
stream_putc(s, attr->link_state->length);

stream_put(s, attr->link_state->data, attr->link_state->length);
}

Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct bgp_attr_srv6_l3vpn {
struct bgp_attr_ls {
unsigned long refcnt;

uint8_t length;
uint16_t length;
void *data;
};

Expand Down
Loading