Skip to content

Commit 9d854ba

Browse files
authored
Merge branch 'FRRouting:master' into master
2 parents 97edb7a + 8f23eb7 commit 9d854ba

6 files changed

+91
-71
lines changed

bgpd/bgp_ecommunity.c

+34-16
Original file line numberDiff line numberDiff line change
@@ -1048,13 +1048,17 @@ static int ecommunity_lb_str(char *buf, size_t bufsz, const uint8_t *pnt,
10481048
return len;
10491049
}
10501050

1051-
static int ipv6_ecommunity_lb_str(char *buf, size_t bufsz, const uint8_t *pnt)
1051+
static int ipv6_ecommunity_lb_str(char *buf, size_t bufsz, const uint8_t *pnt,
1052+
size_t length)
10521053
{
10531054
int len = 0;
1054-
as_t as;
1055-
uint64_t bw;
1055+
as_t as = 0;
1056+
uint64_t bw = 0;
10561057
char bps_buf[20] = { 0 };
10571058

1059+
if (length < IPV6_ECOMMUNITY_SIZE)
1060+
goto done;
1061+
10581062
pnt += 2; /* Reserved */
10591063
pnt = ptr_get_be64(pnt, &bw);
10601064
(void)ptr_get_be32(pnt, &as);
@@ -1071,6 +1075,7 @@ static int ipv6_ecommunity_lb_str(char *buf, size_t bufsz, const uint8_t *pnt)
10711075
else
10721076
snprintfrr(bps_buf, sizeof(bps_buf), "%" PRIu64 " bps", bw * 8);
10731077

1078+
done:
10741079
len = snprintfrr(buf, bufsz, "LB:%u:%" PRIu64 " (%s)", as, bw, bps_buf);
10751080
return len;
10761081
}
@@ -1143,7 +1148,7 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
11431148
char encbuf[128];
11441149

11451150
for (i = 0; i < ecom->size; i++) {
1146-
int unk_ecom = 0;
1151+
bool unk_ecom = false;
11471152
memset(encbuf, 0x00, sizeof(encbuf));
11481153

11491154
/* Space between each value. */
@@ -1153,6 +1158,18 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
11531158
/* Retrieve value field */
11541159
pnt = ecom->val + (i * ecom->unit_size);
11551160

1161+
uint8_t *data = pnt;
1162+
uint8_t *end = data + ecom->unit_size;
1163+
size_t len = end - data;
1164+
1165+
/* Sanity check for extended communities lenght, to avoid
1166+
* overrun when dealing with bits, e.g. ptr_get_be64().
1167+
*/
1168+
if (len < ecom->unit_size) {
1169+
unk_ecom = true;
1170+
goto unknown;
1171+
}
1172+
11561173
/* High-order octet is the type */
11571174
type = *pnt++;
11581175

@@ -1180,14 +1197,14 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
11801197
type == ECOMMUNITY_ENCODE_AS4) {
11811198
ipv6_ecommunity_lb_str(encbuf,
11821199
sizeof(encbuf),
1183-
pnt);
1200+
pnt, len);
11841201
} else if (sub_type == ECOMMUNITY_NODE_TARGET &&
11851202
type == ECOMMUNITY_ENCODE_IP) {
11861203
ecommunity_node_target_str(
11871204
encbuf, sizeof(encbuf), pnt,
11881205
format);
11891206
} else
1190-
unk_ecom = 1;
1207+
unk_ecom = true;
11911208
} else {
11921209
ecommunity_rt_soo_str(encbuf, sizeof(encbuf),
11931210
pnt, type, sub_type,
@@ -1210,7 +1227,7 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
12101227
ecommunity_color_str(encbuf, sizeof(encbuf),
12111228
pnt);
12121229
} else {
1213-
unk_ecom = 1;
1230+
unk_ecom = true;
12141231
}
12151232
} else if (type == ECOMMUNITY_ENCODE_EVPN) {
12161233
if (filter == ECOMMUNITY_ROUTE_TARGET)
@@ -1303,14 +1320,14 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
13031320
"DF: (alg: %u, pref: %u)", alg,
13041321
pref);
13051322
} else
1306-
unk_ecom = 1;
1323+
unk_ecom = true;
13071324
} else if (type == ECOMMUNITY_ENCODE_REDIRECT_IP_NH) {
13081325
sub_type = *pnt++;
13091326
if (sub_type == ECOMMUNITY_REDIRECT_IP_NH) {
13101327
snprintf(encbuf, sizeof(encbuf),
13111328
"FS:redirect IP 0x%x", *(pnt + 5));
13121329
} else
1313-
unk_ecom = 1;
1330+
unk_ecom = true;
13141331
} else if (type == ECOMMUNITY_ENCODE_TRANS_EXP ||
13151332
type == ECOMMUNITY_EXTENDED_COMMUNITY_PART_2 ||
13161333
type == ECOMMUNITY_EXTENDED_COMMUNITY_PART_3) {
@@ -1357,7 +1374,7 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
13571374
snprintf(encbuf, sizeof(encbuf),
13581375
"FS:redirect VRF %s", buf);
13591376
} else if (type != ECOMMUNITY_ENCODE_TRANS_EXP)
1360-
unk_ecom = 1;
1377+
unk_ecom = true;
13611378
else if (sub_type == ECOMMUNITY_TRAFFIC_ACTION) {
13621379
char action[64];
13631380

@@ -1390,36 +1407,37 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
13901407
snprintf(encbuf, sizeof(encbuf),
13911408
"FS:marking %u", *(pnt + 5));
13921409
} else
1393-
unk_ecom = 1;
1410+
unk_ecom = true;
13941411
} else if (type == ECOMMUNITY_ENCODE_AS_NON_TRANS) {
13951412
sub_type = *pnt++;
13961413
if (sub_type == ECOMMUNITY_LINK_BANDWIDTH)
13971414
ecommunity_lb_str(encbuf, sizeof(encbuf), pnt,
13981415
ecom->disable_ieee_floating);
13991416
else if (sub_type == ECOMMUNITY_EXTENDED_LINK_BANDWIDTH)
14001417
ipv6_ecommunity_lb_str(encbuf, sizeof(encbuf),
1401-
pnt);
1418+
pnt, len);
14021419
else
1403-
unk_ecom = 1;
1420+
unk_ecom = true;
14041421
} else if (type == ECOMMUNITY_ENCODE_IP_NON_TRANS) {
14051422
sub_type = *pnt++;
14061423
if (sub_type == ECOMMUNITY_NODE_TARGET)
14071424
ecommunity_node_target_str(
14081425
encbuf, sizeof(encbuf), pnt, format);
14091426
else
1410-
unk_ecom = 1;
1427+
unk_ecom = true;
14111428
} else if (type == ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS) {
14121429
sub_type = *pnt++;
14131430
if (sub_type == ECOMMUNITY_ORIGIN_VALIDATION_STATE)
14141431
ecommunity_origin_validation_state_str(
14151432
encbuf, sizeof(encbuf), pnt);
14161433
else
1417-
unk_ecom = 1;
1434+
unk_ecom = true;
14181435
} else {
14191436
sub_type = *pnt++;
1420-
unk_ecom = 1;
1437+
unk_ecom = true;
14211438
}
14221439

1440+
unknown:
14231441
if (unk_ecom)
14241442
snprintf(encbuf, sizeof(encbuf), "UNK:%d, %d", type,
14251443
sub_type);

ospf6d/ospf6_abr.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1352,9 +1352,10 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa)
13521352
* does not match with the new entry then add the new route
13531353
*/
13541354
if (old_entry_updated == false) {
1355-
if ((old == NULL) || (old->type != route->type)
1356-
|| (old->path.type != route->path.type)
1357-
|| (old->path.cost != route->path.cost))
1355+
if ((old == NULL) || (old->type != route->type) ||
1356+
(old->path.type != route->path.type) ||
1357+
(old->path.cost != route->path.cost) ||
1358+
(old->path.router_bits != route->path.router_bits))
13581359
add_route = true;
13591360
}
13601361

ospf6d/ospf6_route.h

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ extern const char *const ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
290290
prefix_same(&(ra)->prefix, &(rb)->prefix) && \
291291
(ra)->path.type == (rb)->path.type && \
292292
(ra)->path.cost == (rb)->path.cost && \
293+
(ra)->path.router_bits == (rb)->path.router_bits && \
293294
(ra)->path.u.cost_e2 == (rb)->path.u.cost_e2 && \
294295
listcount(ra->paths) == listcount(rb->paths) && \
295296
ospf6_route_cmp_nexthops(ra, rb))

0 commit comments

Comments
 (0)