BGP: Skip empty path segments in received AS_PATH
Although RFC 4271 does not forbid empty path segments, they are useless and some implementations consider them invalid. It is clarified in RFC 7606, specifying that AS_PATH with empty segment is considered malformed.
This commit is contained in:
parent
8f01879c56
commit
775a5a8195
1 changed files with 13 additions and 11 deletions
|
@ -118,7 +118,7 @@ validate_path(struct bgp_proto *p, int as_path, int bs, byte *idata, uint *ileng
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
u8 *a, *dst;
|
u8 *a, *dst;
|
||||||
int len, plen, copy;
|
int len, plen;
|
||||||
|
|
||||||
dst = a = idata;
|
dst = a = idata;
|
||||||
len = *ilength;
|
len = *ilength;
|
||||||
|
@ -132,15 +132,20 @@ validate_path(struct bgp_proto *p, int as_path, int bs, byte *idata, uint *ileng
|
||||||
if (len < plen)
|
if (len < plen)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (a[1] == 0)
|
||||||
|
{
|
||||||
|
log(L_WARN "%s: %s_PATH attribute contains empty segment, skipping it",
|
||||||
|
p->p.name, as_path ? "AS" : "AS4");
|
||||||
|
goto skip;
|
||||||
|
}
|
||||||
|
|
||||||
switch (a[0])
|
switch (a[0])
|
||||||
{
|
{
|
||||||
case AS_PATH_SET:
|
case AS_PATH_SET:
|
||||||
copy = 1;
|
|
||||||
res++;
|
res++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AS_PATH_SEQUENCE:
|
case AS_PATH_SEQUENCE:
|
||||||
copy = 1;
|
|
||||||
res += a[1];
|
res += a[1];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -154,20 +159,17 @@ validate_path(struct bgp_proto *p, int as_path, int bs, byte *idata, uint *ileng
|
||||||
|
|
||||||
log(L_WARN "%s: %s_PATH attribute contains AS_CONFED_* segment, skipping segment",
|
log(L_WARN "%s: %s_PATH attribute contains AS_CONFED_* segment, skipping segment",
|
||||||
p->p.name, as_path ? "AS" : "AS4");
|
p->p.name, as_path ? "AS" : "AS4");
|
||||||
copy = 0;
|
goto skip;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy)
|
if (dst != a)
|
||||||
{
|
memmove(dst, a, plen);
|
||||||
if (dst != a)
|
dst += plen;
|
||||||
memmove(dst, a, plen);
|
|
||||||
dst += plen;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
skip:
|
||||||
len -= plen;
|
len -= plen;
|
||||||
a += plen;
|
a += plen;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue