if (r < 0)
return r;
- if (type_get_type(nl_type) != NETLINK_TYPE_NESTED)
- return -EINVAL;
-
r = message_new_empty(rtnl, &m);
if (r < 0)
return r;
m->hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
- type_get_type_system(nl_type, &m->container_type_system[0]);
+ if (type_get_type(nl_type) == NETLINK_TYPE_NESTED)
+ type_get_type_system(nl_type, &m->container_type_system[0]);
m->hdr->nlmsg_len = size;
m->hdr->nlmsg_type = type;
return offset;
}
-static int message_attribute_has_type(sd_netlink_message *m, size_t *out_size, uint16_t attribute_type, uint16_t data_type) {
+static int message_attribute_has_type(sd_netlink_message *m, uint16_t attribute_type, uint16_t data_type) {
const NLType *type;
int r;
- assert(m);
-
r = type_system_get_type(m->container_type_system[m->n_containers], &type, attribute_type);
if (r < 0)
return r;
if (type_get_type(type) != data_type)
return -EINVAL;
- if (out_size)
- *out_size = type_get_size(type);
- return 0;
+ return type_get_size(type);
}
int sd_netlink_message_append_string(sd_netlink_message *m, unsigned short type, const char *data) {
assert_return(!m->sealed, -EPERM);
assert_return(data, -EINVAL);
- r = message_attribute_has_type(m, &size, type, NETLINK_TYPE_STRING);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_STRING);
if (r < 0)
return r;
+ else
+ size = (size_t)r;
if (size) {
length = strnlen(data, size+1);
assert_return(m, -EINVAL);
assert_return(!m->sealed, -EPERM);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_U8);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_U8);
if (r < 0)
return r;
assert_return(m, -EINVAL);
assert_return(!m->sealed, -EPERM);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_U16);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_U16);
if (r < 0)
return r;
assert_return(m, -EINVAL);
assert_return(!m->sealed, -EPERM);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_U32);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_U32);
if (r < 0)
return r;
assert_return(!m->sealed, -EPERM);
assert_return(data, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_IN_ADDR);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_IN_ADDR);
if (r < 0)
return r;
assert_return(!m->sealed, -EPERM);
assert_return(data, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_IN_ADDR);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_IN_ADDR);
if (r < 0)
return r;
assert_return(!m->sealed, -EPERM);
assert_return(data, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_ETHER_ADDR);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_ETHER_ADDR);
if (r < 0)
return r;
assert_return(!m->sealed, -EPERM);
assert_return(info, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_CACHE_INFO);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_CACHE_INFO);
if (r < 0)
return r;
assert_return(!m->sealed, -EPERM);
assert_return(m->n_containers < RTNL_CONTAINER_DEPTH, -ERANGE);
- r = message_attribute_has_type(m, &size, type, NETLINK_TYPE_NESTED);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_NESTED);
if (r < 0) {
const NLTypeSystemUnion *type_system_union;
int family;
- r = message_attribute_has_type(m, &size, type, NETLINK_TYPE_UNION);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_UNION);
if (r < 0)
return r;
+ size = (size_t) r;
r = sd_rtnl_message_get_family(m, &family);
if (r < 0)
if (r < 0)
return r;
} else {
+ size = (size_t)r;
+
r = type_system_get_type_system(m->container_type_system[m->n_containers],
&m->container_type_system[m->n_containers + 1],
type);
assert_return(m, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_STRING);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_STRING);
if (r < 0)
return r;
assert_return(m, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_U8);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_U8);
if (r < 0)
return r;
assert_return(m, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_U16);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_U16);
if (r < 0)
return r;
assert_return(m, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_U32);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_U32);
if (r < 0)
return r;
assert_return(m, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_ETHER_ADDR);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_ETHER_ADDR);
if (r < 0)
return r;
assert_return(m, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_CACHE_INFO);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_CACHE_INFO);
if (r < 0)
return r;
assert_return(m, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_IN_ADDR);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_IN_ADDR);
if (r < 0)
return r;
assert_return(m, -EINVAL);
- r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_IN_ADDR);
+ r = message_attribute_has_type(m, type, NETLINK_TYPE_IN_ADDR);
if (r < 0)
return r;
r = rtnl_message_parse(m,
&m->rta_offset_tb[m->n_containers],
&m->rta_tb_size[m->n_containers],
- type_system_get_count(type_system),
+ type_system_get_max(type_system),
container,
size);
if (r < 0) {
int rtnl_message_parse(sd_netlink_message *m,
size_t **rta_offset_tb,
unsigned short *rta_tb_size,
- int count,
+ int max,
struct rtattr *rta,
unsigned int rt_len) {
unsigned short type;
size_t *tb;
- tb = new0(size_t, count);
+ tb = new0(size_t, max + 1);
if(!tb)
return -ENOMEM;
- *rta_tb_size = count;
+ *rta_tb_size = max + 1;
for (; RTA_OK(rta, rt_len); rta = RTA_NEXT(rta, rt_len)) {
type = RTA_TYPE(rta);
/* if the kernel is newer than the headers we used
when building, we ignore out-of-range attributes
*/
- if (type >= count)
+ if (type > max)
continue;
if (tb[type])
r = rtnl_message_parse(m,
&m->rta_offset_tb[m->n_containers],
&m->rta_tb_size[m->n_containers],
- type_system_get_count(type_system),
+ type_system_get_max(type_system),
(struct rtattr*)((uint8_t*)NLMSG_DATA(m->hdr) + NLMSG_ALIGN(size)),
NLMSG_PAYLOAD(m->hdr, size));
if (r < 0)