提交 492b558b 编写于 作者: T Thomas Graf 提交者: David S. Miller

[XFRM]: Cleanup xfrm_msg_min and xfrm_dispatch

Converts xfrm_msg_min and xfrm_dispatch to use c99 designated
initializers to make greping a little bit easier. Also replaces
two hardcoded message type with meaningful names.
Signed-off-by: NThomas Graf <tgraf@suug.ch>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 526bdb80
...@@ -144,6 +144,8 @@ enum { ...@@ -144,6 +144,8 @@ enum {
}; };
#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1) #define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
#define XFRM_NR_MSGTYPES (XFRM_MSG_MAX + 1 - XFRM_MSG_BASE)
struct xfrm_user_tmpl { struct xfrm_user_tmpl {
struct xfrm_id id; struct xfrm_id id;
__u16 family; __u16 family;
......
...@@ -855,47 +855,44 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, void **x ...@@ -855,47 +855,44 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, void **x
return 0; return 0;
} }
static const int xfrm_msg_min[(XFRM_MSG_MAX + 1 - XFRM_MSG_BASE)] = { #define XMSGSIZE(type) NLMSG_LENGTH(sizeof(struct type))
NLMSG_LENGTH(sizeof(struct xfrm_usersa_info)), /* NEW SA */
NLMSG_LENGTH(sizeof(struct xfrm_usersa_id)), /* DEL SA */ static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = {
NLMSG_LENGTH(sizeof(struct xfrm_usersa_id)), /* GET SA */ [XFRM_MSG_NEWSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info),
NLMSG_LENGTH(sizeof(struct xfrm_userpolicy_info)),/* NEW POLICY */ [XFRM_MSG_DELSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_id),
NLMSG_LENGTH(sizeof(struct xfrm_userpolicy_id)), /* DEL POLICY */ [XFRM_MSG_GETSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_id),
NLMSG_LENGTH(sizeof(struct xfrm_userpolicy_id)), /* GET POLICY */ [XFRM_MSG_NEWPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_info),
NLMSG_LENGTH(sizeof(struct xfrm_userspi_info)), /* ALLOC SPI */ [XFRM_MSG_DELPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id),
NLMSG_LENGTH(sizeof(struct xfrm_user_acquire)), /* ACQUIRE */ [XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id),
NLMSG_LENGTH(sizeof(struct xfrm_user_expire)), /* EXPIRE */ [XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userspi_info),
NLMSG_LENGTH(sizeof(struct xfrm_userpolicy_info)),/* UPD POLICY */ [XFRM_MSG_ACQUIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_acquire),
NLMSG_LENGTH(sizeof(struct xfrm_usersa_info)), /* UPD SA */ [XFRM_MSG_EXPIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_expire),
NLMSG_LENGTH(sizeof(struct xfrm_user_polexpire)), /* POLEXPIRE */ [XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_info),
NLMSG_LENGTH(sizeof(struct xfrm_usersa_flush)), /* FLUSH SA */ [XFRM_MSG_UPDSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info),
NLMSG_LENGTH(0), /* FLUSH POLICY */ [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),
}; };
#undef XMSGSIZE
static struct xfrm_link { static struct xfrm_link {
int (*doit)(struct sk_buff *, struct nlmsghdr *, void **); int (*doit)(struct sk_buff *, struct nlmsghdr *, void **);
int (*dump)(struct sk_buff *, struct netlink_callback *); int (*dump)(struct sk_buff *, struct netlink_callback *);
} xfrm_dispatch[] = { } xfrm_dispatch[XFRM_NR_MSGTYPES] = {
{ .doit = xfrm_add_sa, }, [XFRM_MSG_NEWSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa },
{ .doit = xfrm_del_sa, }, [XFRM_MSG_DELSA - XFRM_MSG_BASE] = { .doit = xfrm_del_sa },
{ [XFRM_MSG_GETSA - XFRM_MSG_BASE] = { .doit = xfrm_get_sa,
.doit = xfrm_get_sa, .dump = xfrm_dump_sa },
.dump = xfrm_dump_sa, [XFRM_MSG_NEWPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_add_policy },
}, [XFRM_MSG_DELPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy },
{ .doit = xfrm_add_policy }, [XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy,
{ .doit = xfrm_get_policy }, .dump = xfrm_dump_policy },
{ [XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = { .doit = xfrm_alloc_userspi },
.doit = xfrm_get_policy, [XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_add_policy },
.dump = xfrm_dump_policy, [XFRM_MSG_UPDSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa },
}, [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = { .doit = xfrm_flush_sa },
{ .doit = xfrm_alloc_userspi }, [XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_flush_policy },
{},
{},
{ .doit = xfrm_add_policy },
{ .doit = xfrm_add_sa, },
{},
{ .doit = xfrm_flush_sa },
{ .doit = xfrm_flush_policy },
}; };
static int xfrm_done(struct netlink_callback *cb) static int xfrm_done(struct netlink_callback *cb)
...@@ -931,7 +928,9 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *err ...@@ -931,7 +928,9 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *err
return -1; return -1;
} }
if ((type == 2 || type == 5) && (nlh->nlmsg_flags & NLM_F_DUMP)) { if ((type == (XFRM_MSG_GETSA - XFRM_MSG_BASE) ||
type == (XFRM_MSG_GETPOLICY - XFRM_MSG_BASE)) &&
(nlh->nlmsg_flags & NLM_F_DUMP)) {
u32 rlen; u32 rlen;
if (link->dump == NULL) if (link->dump == NULL)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册