static int netlink_container_parse(sd_netlink_message *m, struct netlink_container *container, int count, struct rtattr *rta, unsigned int rt_len) { _cleanup_free_ struct netlink_attribute *attributes = NULL; attributes = new0(struct netlink_attribute, count); if(!attributes) return -ENOMEM; for (; RTA_OK(rta, rt_len); rta = RTA_NEXT(rta, rt_len)) { unsigned short type; 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) continue; if (attributes[type].offset) log_debug("rtnl: message parse - overwriting repeated attribute"); attributes[type].offset = (uint8_t *) rta - (uint8_t *) m->hdr; attributes[type].nested = RTA_FLAGS(rta) & NLA_F_NESTED; attributes[type].net_byteorder = RTA_FLAGS(rta) & NLA_F_NET_BYTEORDER; } container->attributes = attributes; attributes = NULL; container->n_attributes = count; return 0; }
int rtnl_message_parse(sd_rtnl_message *m, size_t **rta_offset_tb, unsigned short *rta_tb_size, int max, struct rtattr *rta, unsigned int rt_len) { unsigned short type; size_t *tb; tb = new0(size_t, max + 1); if(!tb) return -ENOMEM; *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 > max) continue; if (tb[type]) log_debug("rtnl: message parse - overwriting repeated attribute"); tb[type] = (uint8_t *) rta - (uint8_t *) m->hdr; } *rta_offset_tb = tb; return 0; }