+/* The arguments are marked as unused to prevent warnings on platforms where
+ * the Netlink interface isn't supported. */
+static bool
+check_gre_device_netlink(const char *name UNUSED)
+{
+#ifdef GRE_IOCTL_ONLY
+ return false;
+#else
+ static const struct nl_policy getlink_policy[] = {
+ [IFLA_LINKINFO] = { .type = NL_A_NESTED, .optional = false },
+ };
+
+ static const struct nl_policy linkinfo_policy[] = {
+ [IFLA_INFO_KIND] = { .type = NL_A_STRING, .optional = false },
+ };
+
+ int error;
+ bool ret = false;
+ struct ofpbuf request, *reply;
+ struct ifinfomsg ifinfomsg;
+ struct nlattr *getlink_attrs[ARRAY_SIZE(getlink_policy)];
+ struct nlattr *linkinfo_attrs[ARRAY_SIZE(linkinfo_policy)];
+ struct ofpbuf linkinfo;
+ const char *device_kind;
+
+ ofpbuf_init(&request, 0);
+
+ nl_msg_put_nlmsghdr(&request, gre_descriptors.nl_sock,
+ NLMSG_LENGTH(sizeof ifinfomsg), RTM_GETLINK,
+ NLM_F_REQUEST);
+
+ memset(&ifinfomsg, 0, sizeof ifinfomsg);
+ ifinfomsg.ifi_family = AF_UNSPEC;
+ ifinfomsg.ifi_index = do_get_ifindex(name);
+ nl_msg_put(&request, &ifinfomsg, sizeof ifinfomsg);
+
+ error = nl_sock_transact(gre_descriptors.nl_sock, &request, &reply);
+ ofpbuf_uninit(&request);
+ if (error) {
+ VLOG_WARN("couldn't transact netlink socket: %s", strerror(error));
+ return false;
+ }
+
+ if (!nl_policy_parse(reply, NLMSG_HDRLEN + sizeof(struct ifinfomsg),
+ getlink_policy, getlink_attrs,
+ ARRAY_SIZE(getlink_policy))) {
+ VLOG_WARN("received bad rtnl message (getlink policy)");
+ goto error;
+ }
+
+ linkinfo.data = (void *)nl_attr_get(getlink_attrs[IFLA_LINKINFO]);
+ linkinfo.size = nl_attr_get_size(getlink_attrs[IFLA_LINKINFO]);
+ if (!nl_policy_parse(&linkinfo, 0, linkinfo_policy,
+ linkinfo_attrs, ARRAY_SIZE(linkinfo_policy))) {
+ VLOG_WARN("received bad rtnl message (linkinfo policy)");
+ goto error;
+ }
+
+ device_kind = nl_attr_get_string(linkinfo_attrs[IFLA_INFO_KIND]);
+ ret = !strcmp(device_kind, "gretap");
+
+error:
+ ofpbuf_delete(reply);
+ return ret;
+#endif
+}
+
+static bool
+check_gre_device_ioctl(const char *name)
+{
+ struct ethtool_drvinfo drvinfo;
+ int error;
+
+ memset(&drvinfo, 0, sizeof drvinfo);
+ error = netdev_linux_do_ethtool(name, (struct ethtool_cmd *)&drvinfo,
+ ETHTOOL_GDRVINFO, "ETHTOOL_GDRVINFO");
+
+ return !error && !strcmp(drvinfo.driver, "ip_gre")
+ && !strcmp(drvinfo.bus_info, "gretap");
+}
+