X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-rtnl%2Frtnl-message.c;h=e5854de4c6e8fc9edced662682dec5e3b31cac44;hb=0a827d105de9d3d502f22e77fb3ff83da479c2e7;hp=cfce7659aae85c08aadfcfa5996f8b56b03607b8;hpb=aef0768e6c74c5be7c3422926efd46009342e9c6;p=elogind.git diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c index cfce7659a..e5854de4c 100644 --- a/src/libsystemd/sd-rtnl/rtnl-message.c +++ b/src/libsystemd/sd-rtnl/rtnl-message.c @@ -286,6 +286,19 @@ int sd_rtnl_message_new_addr(sd_rtnl *rtnl, sd_rtnl_message **ret, return 0; } +int sd_rtnl_message_new_addr_update(sd_rtnl *rtnl, sd_rtnl_message **ret, + int index, unsigned char family) { + int r; + + r = sd_rtnl_message_new_addr(rtnl, ret, RTM_NEWADDR, index, family); + if (r < 0) + return r; + + (*ret)->hdr->nlmsg_flags |= NLM_F_REPLACE; + + return 0; +} + sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m) { if (m) assert_se(REFCNT_INC(m->n_ref) >= 2); @@ -559,6 +572,24 @@ int sd_rtnl_message_append_ether_addr(sd_rtnl_message *m, unsigned short type, c return 0; } +int sd_rtnl_message_append_cache_info(sd_rtnl_message *m, unsigned short type, const struct ifa_cacheinfo *info) { + int r; + + assert_return(m, -EINVAL); + assert_return(!m->sealed, -EPERM); + assert_return(info, -EINVAL); + + r = message_attribute_has_type(m, type, NLA_CACHE_INFO); + if (r < 0) + return r; + + r = add_rtattr(m, type, info, sizeof(struct ifa_cacheinfo)); + if (r < 0) + return r; + + return 0; +} + int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type) { size_t size; int r; @@ -741,6 +772,25 @@ int sd_rtnl_message_read_ether_addr(sd_rtnl_message *m, unsigned short type, str return 0; } +int sd_rtnl_message_read_cache_info(sd_rtnl_message *m, unsigned short type, struct ifa_cacheinfo *info) { + int r; + void *attr_data; + + r = message_attribute_has_type(m, type, NLA_CACHE_INFO); + if (r < 0) + return r; + + r = rtnl_message_read_internal(m, type, &attr_data); + if (r < 0) + return r; + else if ((size_t)r < sizeof(struct ifa_cacheinfo)) + return -EIO; + + memcpy(info, attr_data, sizeof(struct ifa_cacheinfo)); + + return 0; +} + int sd_rtnl_message_read_in_addr(sd_rtnl_message *m, unsigned short type, struct in_addr *data) { int r; void *attr_data; @@ -911,11 +961,11 @@ int rtnl_message_parse(sd_rtnl_message *m, unsigned short type; size_t *tb; - tb = (size_t *) new0(size_t *, max); + tb = new0(size_t, max + 1); if(!tb) return -ENOMEM; - *rta_tb_size = max; + *rta_tb_size = max + 1; for (; RTA_OK(rta, rt_len); rta = RTA_NEXT(rta, rt_len)) { type = rta->rta_type; @@ -1085,7 +1135,8 @@ int sd_rtnl_message_rewind(sd_rtnl_message *m) { &m->rta_offset_tb[m->n_containers], &m->rta_tb_size[m->n_containers], type_system->max, - (char*)NLMSG_DATA(m->hdr) + NLMSG_ALIGN(type->size), + (struct rtattr*)((uint8_t*)NLMSG_DATA(m->hdr) + + NLMSG_ALIGN(type->size)), NLMSG_PAYLOAD(m->hdr, type->size)); if (r < 0) return r;