+clib_error_t *
+vnet_netlink_get_link_mtu (int ifindex, u32 *mtu)
+{
+ vnet_netlink_msg_t m, *msg;
+ struct ifinfomsg ifmsg = { 0 };
+ struct nlattr *attr;
+ clib_error_t *err = 0;
+ vnet_netlink_msg_t *replies = NULL;
+ int len = 0, offset = 0;
+ u32 msg_mtu;
+
+ ifmsg.ifi_index = ifindex;
+
+ vnet_netlink_msg_init (&m, RTM_GETLINK, NLM_F_REQUEST, &ifmsg,
+ sizeof (struct ifinfomsg));
+ // vnet_netlink_msg_add_rtattr (&m, IFLA_MTU, &mtu, sizeof (int));
+ err = vnet_netlink_msg_send (&m, &replies);
+ if (err)
+ {
+ err = clib_error_return (0, "get link mtu %U", format_clib_error, err);
+ goto done;
+ }
+
+ if (vec_len (replies) != 1)
+ {
+ err = clib_error_return (0, "got %d != 1 netlink reply msg",
+ vec_len (replies));
+ goto done;
+ }
+
+ struct nlmsghdr *nh = (struct nlmsghdr *) replies[0].data;
+ if (nh->nlmsg_type != RTM_NEWLINK)
+ {
+ err = clib_error_return (
+ 0, "netlink reply has wrong type: %d != RTM_NEWLINK", nh->nlmsg_type);
+ goto done;
+ }
+
+ offset = NLMSG_HDRLEN + NLMSG_ALIGN (sizeof (struct ifinfomsg));
+ attr = (struct nlattr *) ((u8 *) nh + offset);
+ len = nh->nlmsg_len - offset;
+
+ do
+ {
+ if ((attr->nla_type & NLA_TYPE_MASK) == IFLA_MTU)
+ {
+ msg_mtu = *(u32 *) ((u8 *) attr + NLA_HDRLEN);
+ if (attr->nla_type & NLA_F_NET_BYTEORDER)
+ *mtu = clib_net_to_host_u32 (msg_mtu);
+ else
+ *mtu = msg_mtu;
+ clib_warning ("mtu: %d", *mtu);
+ goto done;
+ }
+ offset = NLA_ALIGN (attr->nla_len);
+ len -= offset;
+ attr = (struct nlattr *) ((u8 *) attr + offset);
+ }
+ while (len > sizeof (struct nlattr));
+
+ /* not found */
+ err = clib_error_return (0, "mtu not found in netlink message");
+
+done:
+ vec_foreach (msg, replies)
+ {
+ vec_free (msg->data);
+ }
+ vec_free (replies);
+
+ return err;
+}
+