bgpd: Fix memory leak with 'set ip next-hop peer-address'
A route-map with the mentioned statement causes a memory leak for every
prefix that matches.
Signed-off-by: Jorge Boncompte [DTI2] <jorge@dti2.net>
Signed-off-by: David Lamparter <equinox@diac24.net>
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index f95cab1..fa645ac 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -878,7 +878,6 @@
route_map_object_t type, void *object)
{
struct rmap_ip_nexthop_set *rins = rule;
- struct in_addr peer_address;
struct bgp_info *bgp_info;
struct peer *peer;
@@ -894,16 +893,14 @@
&& peer->su_remote
&& sockunion_family (peer->su_remote) == AF_INET)
{
- inet_aton (sockunion_su2str (peer->su_remote), &peer_address);
- bgp_info->attr->nexthop = peer_address;
+ bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_remote);
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
}
else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
&& peer->su_local
&& sockunion_family (peer->su_local) == AF_INET)
{
- inet_aton (sockunion_su2str (peer->su_local), &peer_address);
- bgp_info->attr->nexthop = peer_address;
+ bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_local);
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
}
}
diff --git a/lib/sockunion.h b/lib/sockunion.h
index 4531f62..15b97fc 100644
--- a/lib/sockunion.h
+++ b/lib/sockunion.h
@@ -86,6 +86,8 @@
#define sockunion_family(X) (X)->sa.sa_family
+#define sockunion2ip(X) (X)->sin.sin_addr.s_addr
+
/* Prototypes. */
extern int str2sockunion (const char *, union sockunion *);
extern const char *sockunion2str (union sockunion *, char *, size_t);