+static int
+netdev_geneve_create(struct netdev *netdev)
+{
+ int err;
+ struct ofpbuf request, *reply;
+ size_t linkinfo_off, infodata_off;
+ char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
+ const char *name = netdev_vport_get_dpif_port(netdev,
+ namebuf, sizeof namebuf);
+ struct ifinfomsg *ifinfo;
+ const struct netdev_tunnel_config *tnl_cfg;
+ tnl_cfg = netdev_get_tunnel_config(netdev);
+ if (!tnl_cfg) { /* or assert? */
+ return EINVAL;
+ }
+
+ ofpbuf_init(&request, 0);
+ nl_msg_put_nlmsghdr(&request, 0, RTM_NEWLINK,
+ NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE);
+ ifinfo = ofpbuf_put_zeros(&request, sizeof(struct ifinfomsg));
+ ifinfo->ifi_change = ifinfo->ifi_flags = IFF_UP;
+ nl_msg_put_string(&request, IFLA_IFNAME, name);
+ nl_msg_put_u32(&request, IFLA_MTU, UINT16_MAX);
+ linkinfo_off = nl_msg_start_nested(&request, IFLA_LINKINFO);
+ nl_msg_put_string(&request, IFLA_INFO_KIND, "geneve");
+ infodata_off = nl_msg_start_nested(&request, IFLA_INFO_DATA);
+ nl_msg_put_flag(&request, IFLA_GENEVE_COLLECT_METADATA);
+ nl_msg_put_u8(&request, IFLA_GENEVE_UDP_ZERO_CSUM6_RX, 1);
+ nl_msg_put_be16(&request, IFLA_GENEVE_PORT, tnl_cfg->dst_port);
+ nl_msg_end_nested(&request, infodata_off);
+ nl_msg_end_nested(&request, linkinfo_off);
+
+ err = nl_transact(NETLINK_ROUTE, &request, &reply);
+
+ if (!err) {
+ ofpbuf_uninit(reply);
+ }
+
+ /*
+ * Linux versions older than 4.3 will return EINVAL in case the GENEVE_ID is
+ * not set, which is sufficient to verify COLLECT_METADATA is supported.
+ */
+ if (err == EINVAL) {
+ err = EOPNOTSUPP;
+ }
+
+ ofpbuf_uninit(&request);
+ return err;
+}
+