| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/udata.c`/ |
| 2 | /* |
| 3 | * (C) 2012-2016 by Pablo Neira Ayuso <[email protected]> |
| 4 | * (C) 2016 by Carlos Falgueras GarcĂa <[email protected]> |
| 5 | */ |
| 6 | |
| 7 | #include <libnftnl/udata.h>cxx . . $ `<file>/include/libnftnl/udata.h`/ |
| 8 | #include <udata.h>cxx . . $ `<file>/include/udata.h`/ |
| 9 | #include <utils.h>cxx . . $ `<file>/include/utils.h`/ |
| 10 | |
| 11 | #include <stdlib.h> |
| 12 | #include <stdint.h> |
| 13 | #include <string.h> |
| 14 | |
| 15 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_buf_alloc); |
| 16 | struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *nftnl_udata_buf_alloccxx . . $ nftnl_udata_buf_alloc(51ceef3d25f6abb2).(uint32_tcxx . . $ uint32_t# data_size) |
| 17 | { |
| 18 | struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf; |
| 19 | |
| 20 | buf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct nftnl_udata_bufcxx . . $ nftnl_udata_buf#) + data_size); |
| 21 | if (!buf) |
| 22 | return NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 23 | buf->sizecxx . . $ nftnl_udata_buf#size. = data_size; |
| 24 | buf->endcxx . . $ nftnl_udata_buf#end. = buf->datacxx . . $ nftnl_udata_buf#data.; |
| 25 | |
| 26 | return buf; |
| 27 | } |
| 28 | |
| 29 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_buf_free); |
| 30 | void nftnl_udata_buf_freecxx . . $ nftnl_udata_buf_free(b745cc92da853031).(const struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf) |
| 31 | { |
| 32 | xfreecxx . . $ `include/utils.h:22:9`!(buf); |
| 33 | } |
| 34 | |
| 35 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_buf_len); |
| 36 | uint32_tcxx . . $ uint32_t# nftnl_udata_buf_lencxx . . $ nftnl_udata_buf_len(d0110bc56967f48f).(const struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf) |
| 37 | { |
| 38 | return (uint32_tcxx . . $ uint32_t#)(buf->endcxx . . $ nftnl_udata_buf#end. - buf->datacxx . . $ nftnl_udata_buf#data.); |
| 39 | } |
| 40 | |
| 41 | static uint32_tcxx . . $ uint32_t# nftnl_udata_buf_spacecxx . . $ nftnl_udata_buf_space(d0110bc56967f48f).(const struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf) |
| 42 | { |
| 43 | return buf->sizecxx . . $ nftnl_udata_buf#size. - nftnl_udata_buf_lencxx . . $ nftnl_udata_buf_len(d0110bc56967f48f).(buf); |
| 44 | } |
| 45 | |
| 46 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_buf_data); |
| 47 | void *nftnl_udata_buf_datacxx . . $ nftnl_udata_buf_data(255148d1b5d653d8).(const struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf) |
| 48 | { |
| 49 | return (void *)buf->datacxx . . $ nftnl_udata_buf#data.; |
| 50 | } |
| 51 | |
| 52 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_buf_put); |
| 53 | void nftnl_udata_buf_putcxx . . $ nftnl_udata_buf_put(a0f9f5cbe4151324).(struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf, const void *data, |
| 54 | uint32_tcxx . . $ uint32_t# len) |
| 55 | { |
| 56 | memcpycxx . . $ memcpy(cc817cb175f282d).(buf->datacxx . . $ nftnl_udata_buf#data., data, len <= buf->sizecxx . . $ nftnl_udata_buf#size. ? len : buf->sizecxx . . $ nftnl_udata_buf#size.); |
| 57 | buf->endcxx . . $ nftnl_udata_buf#end. = buf->datacxx . . $ nftnl_udata_buf#data. + len; |
| 58 | } |
| 59 | |
| 60 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_start); |
| 61 | struct nftnl_udatacxx . . $ nftnl_udata# *nftnl_udata_startcxx . . $ nftnl_udata_start(c622af796ce0fb09).(const struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf) |
| 62 | { |
| 63 | return (struct nftnl_udatacxx . . $ nftnl_udata# *)buf->datacxx . . $ nftnl_udata_buf#data.; |
| 64 | } |
| 65 | |
| 66 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_end); |
| 67 | struct nftnl_udatacxx . . $ nftnl_udata# *nftnl_udata_endcxx . . $ nftnl_udata_end(c622af796ce0fb09).(const struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf) |
| 68 | { |
| 69 | return (struct nftnl_udatacxx . . $ nftnl_udata# *)buf->endcxx . . $ nftnl_udata_buf#end.; |
| 70 | } |
| 71 | |
| 72 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_put); |
| 73 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! nftnl_udata_putcxx . . $ nftnl_udata_put(7ecfdf0f1b528a37).(struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf, uint8_tcxx . . $ uint8_t# type, uint32_tcxx . . $ uint32_t# len, |
| 74 | const void *value) |
| 75 | { |
| 76 | struct nftnl_udatacxx . . $ nftnl_udata# *attr; |
| 77 | |
| 78 | if (len > UINT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:122:10`! || |
| 79 | nftnl_udata_buf_spacecxx . . $ nftnl_udata_buf_space(d0110bc56967f48f).(buf) < len + sizeof(struct nftnl_udatacxx . . $ nftnl_udata#)) |
| 80 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 81 | |
| 82 | attr = (struct nftnl_udatacxx . . $ nftnl_udata# *)buf->endcxx . . $ nftnl_udata_buf#end.; |
| 83 | attr->lencxx . . $ nftnl_udata#len. = len; |
| 84 | attr->typecxx . . $ nftnl_udata#type. = type; |
| 85 | memcpycxx . . $ memcpy(cc817cb175f282d).(attr->valuecxx . . $ nftnl_udata#value., value, len); |
| 86 | |
| 87 | buf->endcxx . . $ nftnl_udata_buf#end. = (char *)nftnl_udata_nextcxx . . $ nftnl_udata_next(a137382c6d9f7b41).(attr); |
| 88 | |
| 89 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 90 | } |
| 91 | |
| 92 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_put_strz); |
| 93 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! nftnl_udata_put_strzcxx . . $ nftnl_udata_put_strz(bdc0fa0c1727c).(struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf, uint8_tcxx . . $ uint8_t# type, |
| 94 | const char *strz) |
| 95 | { |
| 96 | return nftnl_udata_putcxx . . $ nftnl_udata_put(7ecfdf0f1b528a37).(buf, type, strlencxx . . $ strlen(751346f8406fd082).(strz) + 1, strz); |
| 97 | } |
| 98 | |
| 99 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_put_u32); |
| 100 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! nftnl_udata_put_u32cxx . . $ nftnl_udata_put_u32(9f300e3bf8c9e5c).(struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf, uint8_tcxx . . $ uint8_t# type, |
| 101 | uint32_tcxx . . $ uint32_t# data) |
| 102 | { |
| 103 | return nftnl_udata_putcxx . . $ nftnl_udata_put(7ecfdf0f1b528a37).(buf, type, sizeof(data), &data); |
| 104 | } |
| 105 | |
| 106 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_type); |
| 107 | uint8_tcxx . . $ uint8_t# nftnl_udata_typecxx . . $ nftnl_udata_type(c0076e911879c2e).(const struct nftnl_udatacxx . . $ nftnl_udata# *attr) |
| 108 | { |
| 109 | return attr->typecxx . . $ nftnl_udata#type.; |
| 110 | } |
| 111 | |
| 112 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_len); |
| 113 | uint8_tcxx . . $ uint8_t# nftnl_udata_lencxx . . $ nftnl_udata_len(c0076e911879c2e).(const struct nftnl_udatacxx . . $ nftnl_udata# *attr) |
| 114 | { |
| 115 | return attr->lencxx . . $ nftnl_udata#len.; |
| 116 | } |
| 117 | |
| 118 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_get); |
| 119 | void *nftnl_udata_getcxx . . $ nftnl_udata_get(625ba16fad4716b3).(const struct nftnl_udatacxx . . $ nftnl_udata# *attr) |
| 120 | { |
| 121 | return (void *)attr->valuecxx . . $ nftnl_udata#value.; |
| 122 | } |
| 123 | |
| 124 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_get_u32); |
| 125 | uint32_tcxx . . $ uint32_t# nftnl_udata_get_u32cxx . . $ nftnl_udata_get_u32(5969fd417ff791c6).(const struct nftnl_udatacxx . . $ nftnl_udata# *attr) |
| 126 | { |
| 127 | uint32_tcxx . . $ uint32_t# data; |
| 128 | |
| 129 | memcpycxx . . $ memcpy(cc817cb175f282d).(&data, attr->valuecxx . . $ nftnl_udata#value., sizeof(data)); |
| 130 | |
| 131 | return data; |
| 132 | } |
| 133 | |
| 134 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_next); |
| 135 | struct nftnl_udatacxx . . $ nftnl_udata# *nftnl_udata_nextcxx . . $ nftnl_udata_next(a137382c6d9f7b41).(const struct nftnl_udatacxx . . $ nftnl_udata# *attr) |
| 136 | { |
| 137 | return (struct nftnl_udatacxx . . $ nftnl_udata# *)&attr->valuecxx . . $ nftnl_udata#value.[attr->lencxx . . $ nftnl_udata#len.]; |
| 138 | } |
| 139 | |
| 140 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_parse); |
| 141 | int nftnl_udata_parsecxx . . $ nftnl_udata_parse(7d42ab81ea594ae6).(const void *data, uint32_tcxx . . $ uint32_t# data_len, nftnl_udata_cb_tcxx . . $ nftnl_udata_cb_t# cb, |
| 142 | void *cb_data) |
| 143 | { |
| 144 | int ret = 0; |
| 145 | const struct nftnl_udatacxx . . $ nftnl_udata# *attr; |
| 146 | |
| 147 | nftnl_udata_for_each_datacxx . . $ `include/libnftnl/udata.h:120:9`!(data, data_len, attr) { |
| 148 | ret = cb(attr, cb_data); |
| 149 | if (ret < 0) |
| 150 | return ret; |
| 151 | } |
| 152 | |
| 153 | return ret; |
| 154 | } |
| 155 | |
| 156 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_nest_start); |
| 157 | struct nftnl_udatacxx . . $ nftnl_udata# *nftnl_udata_nest_startcxx . . $ nftnl_udata_nest_start(b29e268c312a0c7e).(struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf, |
| 158 | uint8_tcxx . . $ uint8_t# type) |
| 159 | { |
| 160 | struct nftnl_udatacxx . . $ nftnl_udata# *ud = nftnl_udata_endcxx . . $ nftnl_udata_end(c622af796ce0fb09).(buf); |
| 161 | |
| 162 | nftnl_udata_putcxx . . $ nftnl_udata_put(7ecfdf0f1b528a37).(buf, type, 0, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!); |
| 163 | |
| 164 | return ud; |
| 165 | } |
| 166 | |
| 167 | EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_udata_nest_end); |
| 168 | void nftnl_udata_nest_endcxx . . $ nftnl_udata_nest_end(86bfb13020c9ca97).(struct nftnl_udata_bufcxx . . $ nftnl_udata_buf# *buf, struct nftnl_udatacxx . . $ nftnl_udata# *ud) |
| 169 | { |
| 170 | ud->lencxx . . $ nftnl_udata#len. = buf->endcxx . . $ nftnl_udata_buf#end. - (char *)ud->valuecxx . . $ nftnl_udata#value.; |
| 171 | } |