From: John Fastabend <john.r.fastabend@intel.com>
To: shemminger@vyatta.com, mst@redhat.com, davem@davemloft.net,
bhutchings@solarflare.com
Cc: sri@us.ibm.com, hadi@cyberus.ca, jeffrey.t.kirsher@intel.com,
netdev@vger.kernel.org, gregory.v.rose@intel.com,
krkumar2@in.ibm.com
Subject: [net-next PATCH v4 3/8] net: add fdb generic dump routine
Date: Sun, 15 Apr 2012 09:44:08 -0700 [thread overview]
Message-ID: <20120415164408.14091.42136.stgit@jf-dev1-dcblab> (raw)
In-Reply-To: <20120415163905.14091.30491.stgit@jf-dev1-dcblab>
This adds a generic dump routine drivers can call. It
should be sufficient to handle any bridging model that
uses the unicast address list. This should be most SR-IOV
enabled NICs.
v2: return error on nlmsg_put and use -EMSGSIZE instead
of -ENOMEM this is inline other usages
Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
---
net/core/rtnetlink.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 037f53c..9149018 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1980,6 +1980,37 @@ errout:
rtnl_set_sk_err(net, RTNLGRP_LINK, err);
}
+static int nlmsg_populate_fdb_fill(struct sk_buff *skb,
+ struct net_device *dev,
+ u8 *addr, u32 pid, u32 seq,
+ int type, unsigned int flags)
+{
+ struct nlmsghdr *nlh;
+ struct ndmsg *ndm;
+
+ nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), NLM_F_MULTI);
+ if (!nlh)
+ return -EMSGSIZE;
+
+ ndm = nlmsg_data(nlh);
+ ndm->ndm_family = AF_BRIDGE;
+ ndm->ndm_pad1 = 0;
+ ndm->ndm_pad2 = 0;
+ ndm->ndm_flags = flags;
+ ndm->ndm_type = 0;
+ ndm->ndm_ifindex = dev->ifindex;
+ ndm->ndm_state = NUD_PERMANENT;
+
+ if (nla_put(skb, NDA_LLADDR, ETH_ALEN, addr))
+ goto nla_put_failure;
+
+ return nlmsg_end(skb, nlh);
+
+nla_put_failure:
+ nlmsg_cancel(skb, nlh);
+ return -EMSGSIZE;
+}
+
static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
{
struct net *net = sock_net(skb->sk);
@@ -2101,6 +2132,59 @@ out:
return err;
}
+static int nlmsg_populate_fdb(struct sk_buff *skb,
+ struct netlink_callback *cb,
+ struct net_device *dev,
+ int *idx,
+ struct netdev_hw_addr_list *list)
+{
+ struct netdev_hw_addr *ha;
+ int err;
+ u32 pid, seq;
+
+ pid = NETLINK_CB(cb->skb).pid;
+ seq = cb->nlh->nlmsg_seq;
+
+ list_for_each_entry(ha, &list->list, list) {
+ if (*idx < cb->args[0])
+ goto skip;
+
+ err = nlmsg_populate_fdb_fill(skb, dev, ha->addr,
+ pid, seq, 0, NTF_SELF);
+ if (err < 0)
+ return err;
+skip:
+ *idx += 1;
+ }
+ return 0;
+}
+
+/**
+ * ndo_dflt_fdb_dump: default netdevice operation to dump an FDB table.
+ * @nlh: netlink message header
+ * @dev: netdevice
+ *
+ * Default netdevice operation to dump the existing unicast address list.
+ * Returns zero on success.
+ */
+int ndo_dflt_fdb_dump(struct sk_buff *skb,
+ struct netlink_callback *cb,
+ struct net_device *dev,
+ int idx)
+{
+ int err;
+
+ netif_addr_lock_bh(dev);
+ err = nlmsg_populate_fdb(skb, cb, dev, &idx, &dev->uc);
+ if (err)
+ goto out;
+ nlmsg_populate_fdb(skb, cb, dev, &idx, &dev->mc);
+out:
+ netif_addr_unlock_bh(dev);
+ return idx;
+}
+EXPORT_SYMBOL(ndo_dflt_fdb_dump);
+
static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
{
int idx = 0;
next prev parent reply other threads:[~2012-04-15 16:57 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-15 16:43 [net-next PATCH v4 0/8] Managing the forwarding database(FDB) John Fastabend
2012-04-15 16:43 ` [net-next PATCH v4 1/8] net: add generic PF_BRIDGE:RTM_ FDB hooks John Fastabend
2012-04-15 16:44 ` [net-next PATCH v4 2/8] net: addr_list: add exclusive dev_uc_add and dev_mc_add John Fastabend
2012-04-15 16:44 ` John Fastabend [this message]
2012-04-15 16:44 ` [net-next PATCH v4 4/8] net: rtnetlink notify events for FDB NTF_SELF adds and deletes John Fastabend
2012-04-15 16:44 ` [net-next PATCH v4 5/8] ixgbe: enable FDB netdevice ops John Fastabend
2012-04-15 16:44 ` [net-next PATCH v4 6/8] ixgbe: allow RAR table to be updated in promisc mode John Fastabend
2012-04-15 16:44 ` [net-next PATCH v4 7/8] ixgbe: UTA table incorrectly programmed John Fastabend
2012-04-15 16:44 ` [net-next PATCH v4 8/8] macvlan: add FDB bridge ops and macvlan flags John Fastabend
2012-04-15 17:06 ` [net-next PATCH v4 0/8] Managing the forwarding database(FDB) David Miller
2012-05-02 15:08 ` Michael S. Tsirkin
2012-05-02 21:52 ` John Fastabend
2012-05-02 23:36 ` Sridhar Samudrala
2012-05-03 19:38 ` John Fastabend
2012-05-04 5:43 ` Sridhar Samudrala
[not found] ` <CAGe6so8q26X=HoQx+P-wkoLMtq1NhRerk98-v0cxhUpvMH4zmQ@mail.gmail.com>
2012-05-05 5:00 ` John Fastabend
2012-05-05 19:53 ` Michael S. Tsirkin
2012-05-03 5:48 ` Michael S. Tsirkin
2012-05-03 19:26 ` John Fastabend
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120415164408.14091.42136.stgit@jf-dev1-dcblab \
--to=john.r.fastabend@intel.com \
--cc=bhutchings@solarflare.com \
--cc=davem@davemloft.net \
--cc=gregory.v.rose@intel.com \
--cc=hadi@cyberus.ca \
--cc=jeffrey.t.kirsher@intel.com \
--cc=krkumar2@in.ibm.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.com \
--cc=sri@us.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).