From: Thomas Graf <tgraf@suug.ch>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, Thomas Graf <tgraf@suug.ch>
Subject: [PATCH 09/16] [XFRM] netlink: Use nlmsg_parse() to parse attributes
Date: Wed, 22 Aug 2007 16:55:47 +0200 [thread overview]
Message-ID: <20070822145631.073291531@lsx.localdomain> (raw)
In-Reply-To: 20070822145538.861270927@lsx.localdomain
[-- Attachment #1: xfrm_parse_attr --]
[-- Type: text/plain, Size: 3192 bytes --]
Uses nlmsg_parse() to parse the attributes. This actually changes
behaviour as unknown attributes (type > MAXTYPE) no longer cause
an error. Instead unknown attributes will be ignored henceforth
to keep older kernels compatible with more recent userspace tools.
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Index: net-2.6.24/net/xfrm/xfrm_user.c
===================================================================
--- net-2.6.24.orig/net/xfrm/xfrm_user.c 2007-08-21 17:07:38.000000000 +0200
+++ net-2.6.24/net/xfrm/xfrm_user.c 2007-08-21 17:31:04.000000000 +0200
@@ -1890,7 +1890,7 @@ static int xfrm_send_migrate(struct xfrm
}
#endif
-#define XMSGSIZE(type) NLMSG_LENGTH(sizeof(struct type))
+#define XMSGSIZE(type) sizeof(struct type)
static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = {
[XFRM_MSG_NEWSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info),
@@ -1906,13 +1906,13 @@ static const int xfrm_msg_min[XFRM_NR_MS
[XFRM_MSG_UPDSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info),
[XFRM_MSG_POLEXPIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_polexpire),
[XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_flush),
- [XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = NLMSG_LENGTH(0),
+ [XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = 0,
[XFRM_MSG_NEWAE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
[XFRM_MSG_GETAE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
[XFRM_MSG_REPORT - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_report),
[XFRM_MSG_MIGRATE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id),
- [XFRM_MSG_GETSADINFO - XFRM_MSG_BASE] = NLMSG_LENGTH(sizeof(u32)),
- [XFRM_MSG_GETSPDINFO - XFRM_MSG_BASE] = NLMSG_LENGTH(sizeof(u32)),
+ [XFRM_MSG_GETSADINFO - XFRM_MSG_BASE] = sizeof(u32),
+ [XFRM_MSG_GETSPDINFO - XFRM_MSG_BASE] = sizeof(u32),
};
#undef XMSGSIZE
@@ -1946,9 +1946,9 @@ static struct xfrm_link {
static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
{
- struct rtattr *xfrma[XFRMA_MAX];
+ struct nlattr *xfrma[XFRMA_MAX+1];
struct xfrm_link *link;
- int type, min_len;
+ int type, err;
type = nlh->nlmsg_type;
if (type > XFRM_MSG_MAX)
@@ -1970,30 +1970,16 @@ static int xfrm_user_rcv_msg(struct sk_b
return netlink_dump_start(xfrm_nl, skb, nlh, link->dump, NULL);
}
- memset(xfrma, 0, sizeof(xfrma));
-
- if (nlh->nlmsg_len < (min_len = xfrm_msg_min[type]))
- return -EINVAL;
-
- if (nlh->nlmsg_len > min_len) {
- int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
- struct rtattr *attr = (void *) nlh + NLMSG_ALIGN(min_len);
-
- while (RTA_OK(attr, attrlen)) {
- unsigned short flavor = attr->rta_type;
- if (flavor) {
- if (flavor > XFRMA_MAX)
- return -EINVAL;
- xfrma[flavor - 1] = attr;
- }
- attr = RTA_NEXT(attr, attrlen);
- }
- }
+ /* FIXME: Temporary hack, nlmsg_parse() starts at xfrma[1], old code
+ * expects first attribute at xfrma[0] */
+ err = nlmsg_parse(nlh, xfrm_msg_min[type], xfrma-1, XFRMA_MAX, NULL);
+ if (err < 0)
+ return err;
if (link->doit == NULL)
return -EINVAL;
- return link->doit(skb, nlh, xfrma);
+ return link->doit(skb, nlh, (struct rtattr **) xfrma);
}
static void xfrm_netlink_rcv(struct sock *sk, int len)
--
next prev parent reply other threads:[~2007-08-22 15:29 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-22 14:55 [PATCH 00/16] xfrm netlink interface cleanups Thomas Graf
2007-08-22 14:55 ` [PATCH 01/16] [XFRM] netlink: Use nlmsg_put() instead of NLMSG_PUT() Thomas Graf
2007-08-22 19:47 ` David Miller
2007-08-22 14:55 ` [PATCH 02/16] [XFRM] netlink: Use nlmsg_end() and nlmsg_cancel() Thomas Graf
2007-08-22 19:47 ` David Miller
2007-08-22 14:55 ` [PATCH 03/16] [XFRM] netlink: Use nlmsg_data() instead of NLMSG_DATA() Thomas Graf
2007-08-22 19:49 ` David Miller
2007-08-22 14:55 ` [PATCH 04/16] [XFRM] netlink: Use nlmsg_broadcast() and nlmsg_unicast() Thomas Graf
2007-08-22 20:54 ` David Miller
2007-08-22 14:55 ` [PATCH 05/16] [XFRM] netlink: Use nla_put()/NLA_PUT() variantes Thomas Graf
2007-08-22 20:55 ` David Miller
2007-08-22 14:55 ` [PATCH 06/16] [XFRM] netlink: Move algorithm length calculation to its own function Thomas Graf
2007-08-22 20:56 ` David Miller
2007-08-22 14:55 ` [PATCH 07/16] [XFRM] netlink: Clear up some of the CONFIG_XFRM_SUB_POLICY ifdef mess Thomas Graf
2007-08-22 20:57 ` David Miller
2007-08-22 14:55 ` [PATCH 08/16] [XFRM] netlink: Use nlmsg_new() and type-safe size calculation helpers Thomas Graf
2007-08-22 20:57 ` David Miller
2007-08-22 14:55 ` Thomas Graf [this message]
2007-08-22 20:58 ` [PATCH 09/16] [XFRM] netlink: Use nlmsg_parse() to parse attributes David Miller
2007-08-22 14:55 ` [PATCH 10/16] [XFRM] netlink: Establish an attribute policy Thomas Graf
2007-08-22 20:59 ` David Miller
2007-08-22 14:55 ` [PATCH 11/16] [XFRM] netlink: Enhance indexing of the attribute array Thomas Graf
2007-08-22 20:59 ` David Miller
2007-08-22 14:55 ` [PATCH 12/16] [XFRM] netlink: Rename attribyte array from xfrma[] to attrs[] Thomas Graf
2007-08-22 21:01 ` David Miller
2007-08-22 14:55 ` [PATCH 13/16] [XFRM] netlink: Use nlattr instead of rtattr Thomas Graf
2007-08-22 21:01 ` David Miller
2007-08-22 14:55 ` [PATCH 14/16] [XFRM] netlink: Use nla_memcpy() in xfrm_update_ae_params() Thomas Graf
2007-08-22 21:02 ` David Miller
2007-08-22 14:55 ` [PATCH 15/16] [XFRM] netlink: Remove dependency on rtnetlink Thomas Graf
2007-08-22 21:02 ` David Miller
2007-08-22 14:55 ` [PATCH 16/16] [XFRM] netlink: Inline attach_encap_tmpl(), attach_sec_ctx(), and attach_one_addr() Thomas Graf
2007-08-22 21:03 ` David Miller
2007-08-24 10:05 ` [PATCH] [XFRM] : Fix pointer copy size for encap_tmpl and coaddr Masahide NAKAMURA
2007-08-24 10:35 ` Thomas Graf
2007-08-25 6:30 ` David Miller
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=20070822145631.073291531@lsx.localdomain \
--to=tgraf@suug.ch \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.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