summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Graf <tgraf@redhat.com>2012-10-09 18:15:50 +0200
committerThomas Graf <tgraf@redhat.com>2012-10-09 18:15:50 +0200
commit6ac07179e580405608a39a377a88b2c65bbdba5c (patch)
treef5ed97ffab6258740c23893f60d12ed6d162435d
parente4192ff97f3fccbe8347e88139aca9ba49af29ab (diff)
downloadlibnl-6ac07179e580405608a39a377a88b2c65bbdba5c.tar.gz
link: Support IFLA_PROMISCUITY link attribute
* read-only attribute * dumped in details sections "promisc-mode (N users)" Signed-off-by: Thomas Graf <tgraf@redhat.com>
-rw-r--r--include/linux/if_link.h18
-rw-r--r--include/netlink-types.h1
-rw-r--r--include/netlink/route/link.h5
-rw-r--r--lib/route/link.c119
4 files changed, 102 insertions, 41 deletions
diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index 8a27d5a..c0a1dd9 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -137,6 +137,11 @@ enum {
IFLA_AF_SPEC,
IFLA_GROUP, /* Group the device belongs to */
IFLA_NET_NS_FD,
+ IFLA_EXT_MASK, /* Extended info mask, VFs, etc */
+ IFLA_PROMISCUITY, /* Promiscuity count: > 0 means acts PROMISC */
+#define IFLA_PROMISCUITY IFLA_PROMISCUITY
+ IFLA_NUM_TX_QUEUES,
+ IFLA_NUM_RX_QUEUES,
__IFLA_MAX
};
@@ -246,6 +251,7 @@ struct ifla_vlan_qos_mapping {
enum {
IFLA_MACVLAN_UNSPEC,
IFLA_MACVLAN_MODE,
+ IFLA_MACVLAN_FLAGS,
__IFLA_MACVLAN_MAX,
};
@@ -258,6 +264,8 @@ enum macvlan_mode {
MACVLAN_MODE_PASSTHRU = 8,/* take over the underlying device */
};
+#define MACVLAN_FLAG_NOPROMISC 1
+
/* SR-IOV virtual function management section */
enum {
@@ -273,6 +281,7 @@ enum {
IFLA_VF_MAC, /* Hardware queue specific attributes */
IFLA_VF_VLAN,
IFLA_VF_TX_RATE, /* TX Bandwidth Allocation */
+ IFLA_VF_SPOOFCHK, /* Spoof Checking on/off switch */
__IFLA_VF_MAX,
};
@@ -294,13 +303,22 @@ struct ifla_vf_tx_rate {
__u32 rate; /* Max TX bandwidth in Mbps, 0 disables throttling */
};
+struct ifla_vf_spoofchk {
+ __u32 vf;
+ __u32 setting;
+};
+#ifdef __KERNEL__
+
+/* We don't want this structure exposed to user space */
struct ifla_vf_info {
__u32 vf;
__u8 mac[32];
__u32 vlan;
__u32 qos;
__u32 tx_rate;
+ __u32 spoofchk;
};
+#endif
/* VF ports management section
*
diff --git a/include/netlink-types.h b/include/netlink-types.h
index e885571..c7f9c4c 100644
--- a/include/netlink-types.h
+++ b/include/netlink-types.h
@@ -173,6 +173,7 @@ struct rtnl_link
void * l_af_data[AF_MAX];
void * l_info;
char * l_ifalias;
+ uint32_t l_promiscuity;
};
struct rtnl_ncacheinfo
diff --git a/include/netlink/route/link.h b/include/netlink/route/link.h
index 42ef7c8..c5824bc 100644
--- a/include/netlink/route/link.h
+++ b/include/netlink/route/link.h
@@ -6,7 +6,7 @@
* License as published by the Free Software Foundation version 2.1
* of the License.
*
- * Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
*/
#ifndef NETLINK_LINK_H_
@@ -197,6 +197,9 @@ extern int rtnl_link_set_stat(struct rtnl_link *, rtnl_link_stat_id_t,
extern int rtnl_link_set_type(struct rtnl_link *, const char *);
extern char * rtnl_link_get_type(struct rtnl_link *);
+extern void rtnl_link_set_promiscuity(struct rtnl_link *, uint32_t);
+extern uint32_t rtnl_link_get_promiscuity(struct rtnl_link *);
+
extern int rtnl_link_enslave_ifindex(struct nl_sock *, int, int);
extern int rtnl_link_enslave(struct nl_sock *, struct rtnl_link *,
struct rtnl_link *);
diff --git a/lib/route/link.c b/lib/route/link.c
index 0e8ac07..7d64aa0 100644
--- a/lib/route/link.c
+++ b/lib/route/link.c
@@ -6,7 +6,7 @@
* License as published by the Free Software Foundation version 2.1
* of the License.
*
- * Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
*/
/**
@@ -28,27 +28,28 @@
#include <netlink/route/link/api.h>
/** @cond SKIP */
-#define LINK_ATTR_MTU 0x0001
-#define LINK_ATTR_LINK 0x0002
-#define LINK_ATTR_TXQLEN 0x0004
-#define LINK_ATTR_WEIGHT 0x0008
-#define LINK_ATTR_MASTER 0x0010
-#define LINK_ATTR_QDISC 0x0020
-#define LINK_ATTR_MAP 0x0040
-#define LINK_ATTR_ADDR 0x0080
-#define LINK_ATTR_BRD 0x0100
-#define LINK_ATTR_FLAGS 0x0200
-#define LINK_ATTR_IFNAME 0x0400
-#define LINK_ATTR_IFINDEX 0x0800
-#define LINK_ATTR_FAMILY 0x1000
-#define LINK_ATTR_ARPTYPE 0x2000
-#define LINK_ATTR_STATS 0x4000
-#define LINK_ATTR_CHANGE 0x8000
-#define LINK_ATTR_OPERSTATE 0x10000
-#define LINK_ATTR_LINKMODE 0x20000
-#define LINK_ATTR_LINKINFO 0x40000
-#define LINK_ATTR_IFALIAS 0x80000
-#define LINK_ATTR_NUM_VF 0x100000
+#define LINK_ATTR_MTU (1 << 0)
+#define LINK_ATTR_LINK (1 << 1)
+#define LINK_ATTR_TXQLEN (1 << 2)
+#define LINK_ATTR_WEIGHT (1 << 3)
+#define LINK_ATTR_MASTER (1 << 4)
+#define LINK_ATTR_QDISC (1 << 5)
+#define LINK_ATTR_MAP (1 << 6)
+#define LINK_ATTR_ADDR (1 << 7)
+#define LINK_ATTR_BRD (1 << 8)
+#define LINK_ATTR_FLAGS (1 << 9)
+#define LINK_ATTR_IFNAME (1 << 10)
+#define LINK_ATTR_IFINDEX (1 << 11)
+#define LINK_ATTR_FAMILY (1 << 12)
+#define LINK_ATTR_ARPTYPE (1 << 13)
+#define LINK_ATTR_STATS (1 << 14)
+#define LINK_ATTR_CHANGE (1 << 15)
+#define LINK_ATTR_OPERSTATE (1 << 16)
+#define LINK_ATTR_LINKMODE (1 << 17)
+#define LINK_ATTR_LINKINFO (1 << 18)
+#define LINK_ATTR_IFALIAS (1 << 19)
+#define LINK_ATTR_NUM_VF (1 << 20)
+#define LINK_ATTR_PROMISCUITY (1 << 21)
static struct nl_cache_ops rtnl_link_ops;
static struct nl_object_ops link_obj_ops;
@@ -236,24 +237,25 @@ static int link_clone(struct nl_object *_dst, struct nl_object *_src)
}
static struct nla_policy link_policy[IFLA_MAX+1] = {
- [IFLA_IFNAME] = { .type = NLA_STRING,
- .maxlen = IFNAMSIZ },
- [IFLA_MTU] = { .type = NLA_U32 },
- [IFLA_TXQLEN] = { .type = NLA_U32 },
- [IFLA_LINK] = { .type = NLA_U32 },
- [IFLA_WEIGHT] = { .type = NLA_U32 },
- [IFLA_MASTER] = { .type = NLA_U32 },
- [IFLA_OPERSTATE]= { .type = NLA_U8 },
- [IFLA_LINKMODE] = { .type = NLA_U8 },
- [IFLA_LINKINFO] = { .type = NLA_NESTED },
- [IFLA_QDISC] = { .type = NLA_STRING,
- .maxlen = IFQDISCSIZ },
- [IFLA_STATS] = { .minlen = sizeof(struct rtnl_link_stats) },
- [IFLA_STATS64] = { .minlen = sizeof(struct rtnl_link_stats64) },
- [IFLA_MAP] = { .minlen = sizeof(struct rtnl_link_ifmap) },
- [IFLA_IFALIAS] = { .type = NLA_STRING, .maxlen = IFALIASZ },
- [IFLA_NUM_VF] = { .type = NLA_U32 },
- [IFLA_AF_SPEC] = { .type = NLA_NESTED },
+ [IFLA_IFNAME] = { .type = NLA_STRING,
+ .maxlen = IFNAMSIZ },
+ [IFLA_MTU] = { .type = NLA_U32 },
+ [IFLA_TXQLEN] = { .type = NLA_U32 },
+ [IFLA_LINK] = { .type = NLA_U32 },
+ [IFLA_WEIGHT] = { .type = NLA_U32 },
+ [IFLA_MASTER] = { .type = NLA_U32 },
+ [IFLA_OPERSTATE] = { .type = NLA_U8 },
+ [IFLA_LINKMODE] = { .type = NLA_U8 },
+ [IFLA_LINKINFO] = { .type = NLA_NESTED },
+ [IFLA_QDISC] = { .type = NLA_STRING,
+ .maxlen = IFQDISCSIZ },
+ [IFLA_STATS] = { .minlen = sizeof(struct rtnl_link_stats) },
+ [IFLA_STATS64] = { .minlen = sizeof(struct rtnl_link_stats64)},
+ [IFLA_MAP] = { .minlen = sizeof(struct rtnl_link_ifmap) },
+ [IFLA_IFALIAS] = { .type = NLA_STRING, .maxlen = IFALIASZ },
+ [IFLA_NUM_VF] = { .type = NLA_U32 },
+ [IFLA_AF_SPEC] = { .type = NLA_NESTED },
+ [IFLA_PROMISCUITY] = { .type = NLA_U32 },
};
static struct nla_policy link_info_policy[IFLA_INFO_MAX+1] = {
@@ -535,6 +537,11 @@ static int link_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
}
}
+ if (tb[IFLA_PROMISCUITY]) {
+ link->l_promiscuity = nla_get_u32(tb[IFLA_PROMISCUITY]);
+ link->l_flags |= LINK_ATTR_PROMISCUITY;
+ }
+
err = pp->pp_cb((struct nl_object *) link, pp);
errout:
rtnl_link_af_ops_put(af_ops);
@@ -619,6 +626,8 @@ static void link_dump_details(struct nl_object *obj, struct nl_dump_params *p)
if (link->ce_mask & LINK_ATTR_IFINDEX)
nl_dump(p, "index %u ", link->l_index);
+ if (link->ce_mask & LINK_ATTR_PROMISCUITY)
+ nl_dump(p, "promisc-mode (%u users) ", link->l_promiscuity);
nl_dump(p, "\n");
@@ -784,6 +793,7 @@ static int link_compare(struct nl_object *_a, struct nl_object *_b,
diff |= LINK_DIFF(BRD, nl_addr_cmp(a->l_bcast, b->l_bcast));
diff |= LINK_DIFF(IFALIAS, strcmp(a->l_ifalias, b->l_ifalias));
diff |= LINK_DIFF(NUM_VF, a->l_num_vf != b->l_num_vf);
+ diff |= LINK_DIFF(PROMISCUITY, a->l_promiscuity != b->l_promiscuity);
if (flags & LOOSE_COMPARISON)
diff |= LINK_DIFF(FLAGS,
@@ -817,6 +827,7 @@ static const struct trans_tbl link_attrs[] = {
__ADD(LINK_ATTR_LINKMODE, linkmode)
__ADD(LINK_ATTR_IFALIAS, ifalias)
__ADD(LINK_ATTR_NUM_VF, num_vf)
+ __ADD(LINK_ATTR_PROMISCUITY, promiscuity)
};
static char *link_attrs2str(int attrs, char *buf, size_t len)
@@ -2011,6 +2022,34 @@ char *rtnl_link_get_type(struct rtnl_link *link)
return link->l_info_kind;
}
+/**
+ * Set link promiscuity count
+ * @arg link Link object
+ * @arg count New promiscuity count
+ *
+ * @copydoc read_only_attribute
+ *
+ * @see rtnl_link_get_promiscuity()
+ */
+void rtnl_link_set_promiscuity(struct rtnl_link *link, uint32_t count)
+{
+ link->l_promiscuity = count;
+ link->l_master |= LINK_ATTR_PROMISCUITY;
+}
+
+/**
+ * Return link promiscuity count
+ * @arg link Link object
+ *
+ * @see rtnl_link_set_promiscuity()
+ * @return Link promiscuity count or 0
+ */
+uint32_t rtnl_link_get_promiscuity(struct rtnl_link *link)
+{
+ return link->l_promiscuity;
+}
+
+
/** @} */
/**