From: Oren Laadan <orenl@cs.columbia.edu>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: containers@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Serge Hallyn <serue@us.ibm.com>,
Matt Helsley <matthltc@us.ibm.com>,
Pavel Emelyanov <xemul@openvz.org>, Dan Smith <danms@us.ibm.com>,
netdev@vger.kernel.org
Subject: [PATCH v21 095/100] c/r: Add rtnl_dellink() helper
Date: Sat, 1 May 2010 10:16:17 -0400 [thread overview]
Message-ID: <1272723382-19470-96-git-send-email-orenl@cs.columbia.edu> (raw)
In-Reply-To: <1272723382-19470-1-git-send-email-orenl@cs.columbia.edu>
From: Dan Smith <danms@us.ibm.com>
This is the kernel equivalent of "ip link del $name" and matches the
existing rtnl_newlink() equivalent of "ip link add $name". It factors
out the message creation and dispatch code a little further into
rtnl_do() before adding the new function.
Cc: netdev@vger.kernel.org
Signed-off-by: Dan Smith <danms@us.ibm.com>
---
net/checkpoint_dev.c | 86 +++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 72 insertions(+), 14 deletions(-)
diff --git a/net/checkpoint_dev.c b/net/checkpoint_dev.c
index 34a6bdb..5097011 100644
--- a/net/checkpoint_dev.c
+++ b/net/checkpoint_dev.c
@@ -475,22 +475,49 @@ static struct sk_buff *new_link_msg(new_link_fn fn, void *data, char *name)
return skb;
}
-static struct net_device *rtnl_newlink(new_link_fn fn, void *data, char *name)
+static struct sk_buff *del_link_msg(char *name)
+{
+ int ret = -ENOMEM;
+ int flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK;
+ struct nlmsghdr *nlh;
+ struct sk_buff *skb;
+ struct ifinfomsg *ifm;
+
+ skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+ if (!skb)
+ return ERR_PTR(-ENOMEM);
+
+ nlh = nlmsg_put(skb, 0, 0, RTM_DELLINK, sizeof(*ifm), flags);
+ if (!nlh)
+ goto out;
+
+ ifm = nlmsg_data(nlh);
+ memset(ifm, 0, sizeof(*ifm));
+
+ ret = nla_put_string(skb, IFLA_IFNAME, name);
+ if (ret)
+ goto out;
+
+ nlmsg_end(skb, nlh);
+
+ out:
+ if (ret < 0) {
+ kfree_skb(skb);
+ skb = ERR_PTR(ret);
+ }
+
+ return skb;
+}
+
+static int rtnl_do(struct sk_buff *skb)
{
int ret = -ENOMEM;
struct socket *rtnl = NULL;
- struct sk_buff *skb = NULL;
+ struct sk_buff *rskb = NULL;
struct nlmsghdr *nlh;
struct msghdr msg;
struct kvec kvec;
- skb = new_link_msg(fn, data, name);
- if (IS_ERR(skb)) {
- ckpt_debug("failed to create new link message: %li\n",
- PTR_ERR(skb));
- return ERR_PTR(PTR_ERR(skb));
- }
-
memset(&msg, 0, sizeof(msg));
kvec.iov_len = skb->len;
kvec.iov_base = skb->head;
@@ -510,25 +537,56 @@ static struct net_device *rtnl_newlink(new_link_fn fn, void *data, char *name)
goto out;
}
- /* Free the send skb to make room for the receive skb */
- kfree_skb(skb);
-
- nlh = rtnl_get_response(rtnl, &skb);
+ nlh = rtnl_get_response(rtnl, &rskb);
if (IS_ERR(nlh)) {
ret = PTR_ERR(nlh);
ckpt_debug("RTNETLINK said: %i\n", ret);
}
out:
rtnl_close(rtnl);
+ kfree_skb(rskb);
out_noclose:
- kfree_skb(skb);
+ return ret;
+}
+static struct net_device *rtnl_newlink(new_link_fn fn, void *data, char *name)
+{
+ struct sk_buff *skb;
+ int ret;
+
+ skb = new_link_msg(fn, data, name);
+ if (IS_ERR(skb)) {
+ ckpt_debug("failed to create new link message: %li\n",
+ PTR_ERR(skb));
+ return ERR_PTR(PTR_ERR(skb));
+ }
+
+ ret = rtnl_do(skb);
+ kfree_skb(skb);
if (ret < 0)
return ERR_PTR(ret);
else
return dev_get_by_name(current->nsproxy->net_ns, name);
}
+static int rtnl_dellink(char *name)
+{
+ struct sk_buff *skb;
+ int ret;
+
+ skb = del_link_msg(name);
+ if (IS_ERR(skb)) {
+ ckpt_debug("failed to create del link message: %li\n",
+ PTR_ERR(skb));
+ return PTR_ERR(skb);
+ }
+
+ ret = rtnl_do(skb);
+ kfree_skb(skb);
+
+ return ret;
+}
+
static int netdev_noop(void *data)
{
return 0;
--
1.6.3.3
next prev parent reply other threads:[~2010-05-01 14:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1272723382-19470-1-git-send-email-orenl@cs.columbia.edu>
2010-05-01 14:15 ` [PATCH v21 020/100] c/r: documentation Oren Laadan
2010-05-06 20:27 ` Randy Dunlap
2010-05-07 6:54 ` Oren Laadan
2010-05-01 14:15 ` [PATCH v21 022/100] c/r: basic infrastructure for checkpoint/restart Oren Laadan
2010-05-01 14:15 ` [PATCH v21 071/100] Add common socket helpers to unify the security hooks Oren Laadan
2010-05-01 14:15 ` [PATCH v21 072/100] c/r: introduce checkpoint/restore methods to struct proto_ops Oren Laadan
2010-05-01 14:15 ` [PATCH v21 073/100] c/r: Add AF_UNIX support (v12) Oren Laadan
2010-05-01 14:15 ` [PATCH v21 074/100] c/r: add support for listening INET sockets (v2) Oren Laadan
2010-05-01 14:15 ` [PATCH v21 075/100] c/r: add support for connected INET sockets (v5) Oren Laadan
2010-05-01 14:16 ` [PATCH v21 093/100] c/r: Add checkpoint and collect hooks to net_device_ops Oren Laadan
2010-05-01 14:16 ` [PATCH v21 094/100] c/r: Basic support for network namespaces and devices (v6) Oren Laadan
2010-05-01 14:16 ` Oren Laadan [this message]
2010-05-01 14:16 ` [PATCH v21 096/100] c/r: Add checkpoint support for veth devices (v2) Oren Laadan
2010-05-01 14:16 ` [PATCH v21 097/100] c/r: Add loopback checkpoint support (v2) Oren Laadan
2010-05-01 14:16 ` [PATCH v21 098/100] c/r: Add a checkpoint handler to the 'sit' device Oren Laadan
2010-05-01 14:16 ` [PATCH v21 099/100] c/r: Add checkpoint support to macvlan driver Oren Laadan
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=1272723382-19470-96-git-send-email-orenl@cs.columbia.edu \
--to=orenl@cs.columbia.edu \
--cc=akpm@linux-foundation.org \
--cc=containers@lists.linux-foundation.org \
--cc=danms@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matthltc@us.ibm.com \
--cc=netdev@vger.kernel.org \
--cc=serue@us.ibm.com \
--cc=xemul@openvz.org \
/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).