From 1a2a3c892efe798796f252352785fac030059a2b Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 20 Sep 2019 06:41:02 -0400 Subject: [PATCH] bgpd: Invalid NH's should send an apropriate reason code RFC 4271 sec 6.3 p33, In the case of a BGP_NEXTHOP attribute with an incorrect value, FRR is supposed to send a notification and include 'Corresponding type, length and value of the NEXT_HOP attribute in the notification data. Fixes: #4997 Signed-off-by: Nikos Signed-off-by: Donald Sharp --- bgpd/bgp_attr.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index ea7f761abf..3f21810f34 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1269,14 +1269,20 @@ bgp_attr_nexthop_valid(struct peer *peer, struct attr *attr) if ((IPV4_NET0(nexthop_h) || IPV4_NET127(nexthop_h) || IPV4_CLASS_DE(nexthop_h)) && !BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) { + uint8_t data[7]; /* type(2) + length(1) + nhop(4) */ char buf[INET_ADDRSTRLEN]; inet_ntop(AF_INET, &attr->nexthop.s_addr, buf, INET_ADDRSTRLEN); flog_err(EC_BGP_ATTR_MARTIAN_NH, "Martian nexthop %s", buf); - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, - BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP); + data[0] = BGP_ATTR_FLAG_TRANS; + data[1] = BGP_ATTR_NEXT_HOP; + data[2] = BGP_ATTR_NHLEN_IPV4; + memcpy(&data[3], &attr->nexthop.s_addr, BGP_ATTR_NHLEN_IPV4); + bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR, + BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, + data, 7); return BGP_ATTR_PARSE_ERROR; } -- 2.39.5