/*
- * Copyright (c) 2008 Nicira Networks.
+ * Copyright (c) 2008, 2010, 2011, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/* Netlink protocol definitions.
*
- * These definitions are equivalent to those in the Linux 2.6 kernel headers,
- * without requiring those headers to be available. */
+ * Netlink is a message framing format described in RFC 3549 and used heavily
+ * in Linux to access the network stack. Open vSwitch uses AF_NETLINK sockets
+ * for this purpose on Linux. But on all platforms, Open vSwitch uses Netlink
+ * message framing internally for certain purposes.
+ *
+ * This header provides access to the Netlink message framing definitions
+ * regardless of platform. On Linux, it includes the proper headers directly;
+ * on other platforms it directly defines the structures and macros itself.
+ */
#include <stdint.h>
#include <sys/socket.h>
#include "util.h"
-#define NETLINK_GENERIC 16
+#ifdef HAVE_NETLINK
+#include <linux/netlink.h>
+#include <linux/genetlink.h>
-struct sockaddr_nl {
- sa_family_t nl_family;
- unsigned short int nl_pad;
- uint32_t nl_pid;
- uint32_t nl_groups;
-};
-BUILD_ASSERT_DECL(sizeof(struct sockaddr_nl) == 12);
+#else
+#define NETLINK_GENERIC 16
/* nlmsg_flags bits. */
#define NLM_F_REQUEST 0x001
#define NLM_F_ROOT 0x100
#define NLM_F_MATCH 0x200
+#define NLM_F_EXCL 0x200
#define NLM_F_ATOMIC 0x400
+#define NLM_F_CREATE 0x400
#define NLM_F_DUMP (NLM_F_ROOT | NLM_F_MATCH)
/* nlmsg_type values. */
#define NLMSG_MIN_TYPE 0x10
+#define MAX_LINKS 32
+
struct nlmsghdr {
uint32_t nlmsg_len;
uint16_t nlmsg_type;
};
BUILD_ASSERT_DECL(sizeof(struct nlmsgerr) == 20);
-#define NETLINK_ADD_MEMBERSHIP 1
-#define NETLINK_DROP_MEMBERSHIP 2
-#define NETLINK_PKTINFO 3
-
struct genlmsghdr {
uint8_t cmd;
uint8_t version;
};
#define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
+#endif /* !HAVE_NETLINK */
+
+/* These were introduced all together in 2.6.24. */
+#ifndef NLA_TYPE_MASK
+#define NLA_F_NESTED (1 << 15)
+#define NLA_F_NET_BYTEORDER (1 << 14)
+#define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
+#endif
+
+/* These were introduced all together in 2.6.14. (We want our programs to
+ * support the newer kernel features even if compiled with older headers.) */
+#ifndef NETLINK_ADD_MEMBERSHIP
+#define NETLINK_ADD_MEMBERSHIP 1
+#define NETLINK_DROP_MEMBERSHIP 2
+#endif
+
+/* These were introduced all together in 2.6.23. (We want our programs to
+ * support the newer kernel features even if compiled with older headers.) */
+#ifndef CTRL_ATTR_MCAST_GRP_MAX
+
+#undef CTRL_ATTR_MAX
+#define CTRL_ATTR_MAX 7
+#define CTRL_ATTR_MCAST_GROUPS 7
+
+enum {
+ CTRL_ATTR_MCAST_GRP_UNSPEC,
+ CTRL_ATTR_MCAST_GRP_NAME,
+ CTRL_ATTR_MCAST_GRP_ID,
+ __CTRL_ATTR_MCAST_GRP_MAX,
+};
+
+#define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)
+#endif /* CTRL_ATTR_MCAST_GRP_MAX */
#endif /* netlink-protocol.h */