Commit a4318300 by Stéphane Graber

Revert "audit: added capacity and reserve() to nlmsg"

This reverts commit 55ae7edb. This change caused hangs in the testsuite, specifically with lxc-user-nic. Signed-off-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 26f1b390
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
extern size_t nlmsg_len(const struct nlmsg *nlmsg) extern size_t nlmsg_len(const struct nlmsg *nlmsg)
{ {
return nlmsg->nlmsghdr->nlmsg_len - NLMSG_HDRLEN; return nlmsg->nlmsghdr.nlmsg_len - NLMSG_HDRLEN;
} }
extern void *nlmsg_data(struct nlmsg *nlmsg) extern void *nlmsg_data(struct nlmsg *nlmsg)
...@@ -53,16 +53,13 @@ static int nla_put(struct nlmsg *nlmsg, int attr, ...@@ -53,16 +53,13 @@ static int nla_put(struct nlmsg *nlmsg, int attr,
{ {
struct rtattr *rta; struct rtattr *rta;
size_t rtalen = RTA_LENGTH(len); size_t rtalen = RTA_LENGTH(len);
size_t tlen = NLMSG_ALIGN(nlmsg->nlmsghdr->nlmsg_len) + RTA_ALIGN(rtalen);
if (tlen > nlmsg->cap) rta = NLMSG_TAIL(&nlmsg->nlmsghdr);
return -ENOMEM; rta->rta_type = attr;
rta->rta_len = rtalen;
rta = NLMSG_TAIL(nlmsg->nlmsghdr); memcpy(RTA_DATA(rta), data, len);
rta->rta_type = attr; nlmsg->nlmsghdr.nlmsg_len =
rta->rta_len = rtalen; NLMSG_ALIGN(nlmsg->nlmsghdr.nlmsg_len) + RTA_ALIGN(rtalen);
memcpy(RTA_DATA(rta), data, len);
nlmsg->nlmsghdr->nlmsg_len = tlen;
return 0; return 0;
} }
...@@ -94,7 +91,7 @@ extern int nla_put_attr(struct nlmsg *nlmsg, int attr) ...@@ -94,7 +91,7 @@ extern int nla_put_attr(struct nlmsg *nlmsg, int attr)
struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr) struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr)
{ {
struct rtattr *rtattr = NLMSG_TAIL(nlmsg->nlmsghdr); struct rtattr *rtattr = NLMSG_TAIL(&nlmsg->nlmsghdr);
if (nla_put_attr(nlmsg, attr)) if (nla_put_attr(nlmsg, attr))
return NULL; return NULL;
...@@ -104,7 +101,7 @@ struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr) ...@@ -104,7 +101,7 @@ struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr)
void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr) void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr)
{ {
attr->rta_len = (void *)NLMSG_TAIL(nlmsg->nlmsghdr) - (void *)attr; attr->rta_len = (void *)NLMSG_TAIL(&nlmsg->nlmsghdr) - (void *)attr;
} }
extern struct nlmsg *nlmsg_alloc(size_t size) extern struct nlmsg *nlmsg_alloc(size_t size)
...@@ -112,48 +109,18 @@ extern struct nlmsg *nlmsg_alloc(size_t size) ...@@ -112,48 +109,18 @@ extern struct nlmsg *nlmsg_alloc(size_t size)
struct nlmsg *nlmsg; struct nlmsg *nlmsg;
size_t len = NLMSG_HDRLEN + NLMSG_ALIGN(size); size_t len = NLMSG_HDRLEN + NLMSG_ALIGN(size);
nlmsg = (struct nlmsg *)malloc(sizeof(struct nlmsg)); nlmsg = (struct nlmsg *)malloc(len);
if (!nlmsg) if (!nlmsg)
return NULL; return NULL;
nlmsg->nlmsghdr = (struct nlmsghdr *)malloc(len); memset(nlmsg, 0, len);
if (!nlmsg->nlmsghdr) nlmsg->nlmsghdr.nlmsg_len = NLMSG_HDRLEN;
goto errout;
memset(nlmsg->nlmsghdr, 0, len);
nlmsg->cap = len;
nlmsg->nlmsghdr->nlmsg_len = NLMSG_HDRLEN;
return nlmsg; return nlmsg;
errout:
free(nlmsg);
return NULL;
}
extern void *nlmsg_reserve(struct nlmsg *nlmsg, size_t len)
{
void *buf;
size_t nlmsg_len = nlmsg->nlmsghdr->nlmsg_len;
size_t tlen = NLMSG_ALIGN(len);
if (nlmsg_len + tlen > nlmsg->cap)
return NULL;
buf = nlmsg->nlmsghdr + nlmsg_len;
nlmsg->nlmsghdr->nlmsg_len += tlen;
if (tlen > len)
memset(buf + len, 0, tlen - len);
return buf;
} }
extern void nlmsg_free(struct nlmsg *nlmsg) extern void nlmsg_free(struct nlmsg *nlmsg)
{ {
if (!nlmsg)
return;
free(nlmsg->nlmsghdr);
free(nlmsg); free(nlmsg);
} }
...@@ -163,7 +130,7 @@ extern int netlink_rcv(struct nl_handler *handler, struct nlmsg *answer) ...@@ -163,7 +130,7 @@ extern int netlink_rcv(struct nl_handler *handler, struct nlmsg *answer)
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr;
struct iovec iov = { struct iovec iov = {
.iov_base = answer, .iov_base = answer,
.iov_len = answer->nlmsghdr->nlmsg_len, .iov_len = answer->nlmsghdr.nlmsg_len,
}; };
struct msghdr msg = { struct msghdr msg = {
...@@ -190,7 +157,7 @@ again: ...@@ -190,7 +157,7 @@ again:
return 0; return 0;
if (msg.msg_flags & MSG_TRUNC && if (msg.msg_flags & MSG_TRUNC &&
ret == answer->nlmsghdr->nlmsg_len) ret == answer->nlmsghdr.nlmsg_len)
return -EMSGSIZE; return -EMSGSIZE;
return ret; return ret;
...@@ -201,7 +168,7 @@ extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg) ...@@ -201,7 +168,7 @@ extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg)
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr;
struct iovec iov = { struct iovec iov = {
.iov_base = (void*)nlmsg, .iov_base = (void*)nlmsg,
.iov_len = nlmsg->nlmsghdr->nlmsg_len, .iov_len = nlmsg->nlmsghdr.nlmsg_len,
}; };
struct msghdr msg = { struct msghdr msg = {
.msg_name = &nladdr, .msg_name = &nladdr,
...@@ -239,7 +206,7 @@ extern int netlink_transaction(struct nl_handler *handler, ...@@ -239,7 +206,7 @@ extern int netlink_transaction(struct nl_handler *handler,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (answer->nlmsghdr->nlmsg_type == NLMSG_ERROR) { if (answer->nlmsghdr.nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(answer); struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(answer);
return err->error; return err->error;
} }
......
...@@ -53,16 +53,14 @@ struct nl_handler { ...@@ -53,16 +53,14 @@ struct nl_handler {
}; };
/* /*
* struct nlmsg : the netlink message structure. This message is to be used to * struct nlmsg : the netlink message structure, it consists just
* on a definition for a nlmsghdr. This message is to be used to
* be allocated with netlink_alloc. * be allocated with netlink_alloc.
* * @nlmsghdr : a pointer to a netlink message header, this field
* @nlmsghdr: a pointer to a netlink message header * _must_ be always the first field of this structure
* @cap: capacity of the netlink message, this is the initially allocated size
* and later operations (e.g. reserve and put) can not exceed this limit.
*/ */
struct nlmsg { struct nlmsg {
struct nlmsghdr *nlmsghdr; struct nlmsghdr nlmsghdr;
ssize_t cap;
}; };
/* /*
...@@ -222,16 +220,6 @@ void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr); ...@@ -222,16 +220,6 @@ void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr);
struct nlmsg *nlmsg_alloc(size_t size); struct nlmsg *nlmsg_alloc(size_t size);
/* /*
* Reserve room for additional data at the tail of a netlink message
*
* @nlmsg: the netlink message
* @len: length of additional data to reserve room for
*
* Returns a pointer to newly reserved room or NULL
*/
void *nlmsg_reserve(struct nlmsg *nlmsg, size_t len);
/*
* nlmsg_free : free a previously allocate message * nlmsg_free : free a previously allocate message
* *
* @nlmsg: the netlink message to be freed * @nlmsg: the netlink message to be freed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment