The netlink requests are not that big. Use stack allocated stub array to avoid the allocations whatsoever. The array has some space reserve in case the attributes need to grow in size in future.
Signed-off-by: Ales Musil <[email protected]> --- controller/route-exchange-netlink.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/controller/route-exchange-netlink.c b/controller/route-exchange-netlink.c index 0b9b21b86..d786e44d6 100644 --- a/controller/route-exchange-netlink.c +++ b/controller/route-exchange-netlink.c @@ -37,6 +37,7 @@ VLOG_DEFINE_THIS_MODULE(route_exchange_netlink); +#define NETNL_REQ_BUFFER_SIZE 128 #define TABLE_ID_VALID(table_id) (table_id != RT_TABLE_UNSPEC && \ table_id != RT_TABLE_COMPAT && \ table_id != RT_TABLE_DEFAULT && \ @@ -57,10 +58,12 @@ re_nl_create_vrf(const char *ifname, uint32_t table_id) size_t linkinfo_off, infodata_off; struct ifinfomsg *ifinfo; - struct ofpbuf request; int err; - ofpbuf_init(&request, 0); + struct ofpbuf request; + uint8_t request_stub[NETNL_REQ_BUFFER_SIZE]; + ofpbuf_use_stub(&request, request_stub, sizeof(request_stub)); + nl_msg_put_nlmsghdr(&request, 0, RTM_NEWLINK, NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE | NLM_F_EXCL); ifinfo = ofpbuf_put_zeros(&request, sizeof *ifinfo); @@ -84,10 +87,12 @@ int re_nl_delete_vrf(const char *ifname) { struct ifinfomsg *ifinfo; - struct ofpbuf request; int err; - ofpbuf_init(&request, 0); + struct ofpbuf request; + uint8_t request_stub[NETNL_REQ_BUFFER_SIZE]; + ofpbuf_use_stub(&request, request_stub, sizeof(request_stub)); + nl_msg_put_nlmsghdr(&request, 0, RTM_DELLINK, NLM_F_REQUEST | NLM_F_ACK); ifinfo = ofpbuf_put_zeros(&request, sizeof *ifinfo); nl_msg_put_string(&request, IFLA_IFNAME, ifname); @@ -104,13 +109,15 @@ modify_route(uint32_t type, uint32_t flags_arg, uint32_t table_id, { uint32_t flags = NLM_F_REQUEST | NLM_F_ACK; bool is_ipv4 = IN6_IS_ADDR_V4MAPPED(dst); - struct ofpbuf request; struct rtmsg *rt; int err; flags |= flags_arg; - ofpbuf_init(&request, 0); + struct ofpbuf request; + uint8_t request_stub[NETNL_REQ_BUFFER_SIZE]; + ofpbuf_use_stub(&request, request_stub, sizeof(request_stub)); + nl_msg_put_nlmsghdr(&request, 0, type, flags); rt = ofpbuf_put_zeros(&request, sizeof *rt); rt->rtm_family = is_ipv4 ? AF_INET : AF_INET6; -- 2.50.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
