|
| 1 | +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) |
| 2 | +/* Do not edit directly, auto-generated from: */ |
| 3 | +/* */ |
| 4 | +/* YNL-GEN user source */ |
| 5 | + |
| 6 | +#include "rt-addr-user.hpp" |
| 7 | + |
| 8 | +#include <array> |
| 9 | + |
| 10 | +#include <linux/rtnetlink.h> |
| 11 | + |
| 12 | +#include <linux/genetlink.h> |
| 13 | + |
| 14 | +namespace ynl_cpp { |
| 15 | + |
| 16 | +/* Enums */ |
| 17 | +static constexpr std::array<std::string_view, RTM_GETMULTICAST + 1> rt_addr_op_strmap = []() { |
| 18 | + std::array<std::string_view, RTM_GETMULTICAST + 1> arr{}; |
| 19 | + arr[20] = "getaddr"; |
| 20 | + arr[RTM_GETMULTICAST] = "getmulticast"; |
| 21 | + return arr; |
| 22 | +} (); |
| 23 | + |
| 24 | +std::string_view rt_addr_op_str(int op) |
| 25 | +{ |
| 26 | + if (op < 0 || op >= (int)(rt_addr_op_strmap.size())) |
| 27 | + return ""; |
| 28 | + return rt_addr_op_strmap[op]; |
| 29 | +} |
| 30 | + |
| 31 | +static constexpr std::array<std::string_view, 11 + 1> rt_addr_ifa_flags_strmap = []() { |
| 32 | + std::array<std::string_view, 11 + 1> arr{}; |
| 33 | + arr[0] = "secondary"; |
| 34 | + arr[1] = "nodad"; |
| 35 | + arr[2] = "optimistic"; |
| 36 | + arr[3] = "dadfailed"; |
| 37 | + arr[4] = "homeaddress"; |
| 38 | + arr[5] = "deprecated"; |
| 39 | + arr[6] = "tentative"; |
| 40 | + arr[7] = "permanent"; |
| 41 | + arr[8] = "managetempaddr"; |
| 42 | + arr[9] = "noprefixroute"; |
| 43 | + arr[10] = "mcautojoin"; |
| 44 | + arr[11] = "stable-privacy"; |
| 45 | + return arr; |
| 46 | +} (); |
| 47 | + |
| 48 | +std::string_view rt_addr_ifa_flags_str(int value) |
| 49 | +{ |
| 50 | + value = (int)(ffs(value) - 1); |
| 51 | + if (value < 0 || value >= (int)(rt_addr_ifa_flags_strmap.size())) |
| 52 | + return ""; |
| 53 | + return rt_addr_ifa_flags_strmap[value]; |
| 54 | +} |
| 55 | + |
| 56 | +/* Policies */ |
| 57 | +static std::array<ynl_policy_attr,IFA_MAX + 1> rt_addr_addr_attrs_policy = []() { |
| 58 | + std::array<ynl_policy_attr,IFA_MAX + 1> arr{}; |
| 59 | + arr[IFA_ADDRESS].name = "address"; |
| 60 | + arr[IFA_ADDRESS].type = YNL_PT_BINARY; |
| 61 | + arr[IFA_LOCAL].name = "local"; |
| 62 | + arr[IFA_LOCAL].type = YNL_PT_BINARY; |
| 63 | + arr[IFA_LABEL].name = "label"; |
| 64 | + arr[IFA_LABEL].type = YNL_PT_NUL_STR; |
| 65 | + arr[IFA_BROADCAST].name = "broadcast"; |
| 66 | + arr[IFA_BROADCAST].type = YNL_PT_BINARY; |
| 67 | + arr[IFA_ANYCAST].name = "anycast"; |
| 68 | + arr[IFA_ANYCAST].type = YNL_PT_BINARY; |
| 69 | + arr[IFA_CACHEINFO].name = "cacheinfo"; |
| 70 | + arr[IFA_CACHEINFO].type = YNL_PT_BINARY; |
| 71 | + arr[IFA_MULTICAST].name = "multicast"; |
| 72 | + arr[IFA_MULTICAST].type = YNL_PT_BINARY; |
| 73 | + arr[IFA_FLAGS].name = "flags"; |
| 74 | + arr[IFA_FLAGS].type = YNL_PT_U32; |
| 75 | + arr[IFA_RT_PRIORITY].name = "rt-priority"; |
| 76 | + arr[IFA_RT_PRIORITY].type = YNL_PT_U32; |
| 77 | + arr[IFA_TARGET_NETNSID].name = "target-netnsid"; |
| 78 | + arr[IFA_TARGET_NETNSID].type = YNL_PT_BINARY; |
| 79 | + arr[IFA_PROTO].name = "proto"; |
| 80 | + arr[IFA_PROTO].type = YNL_PT_U8; |
| 81 | + return arr; |
| 82 | +} (); |
| 83 | + |
| 84 | +struct ynl_policy_nest rt_addr_addr_attrs_nest = { |
| 85 | + .max_attr = static_cast<unsigned int>(IFA_MAX), |
| 86 | + .table = rt_addr_addr_attrs_policy.data(), |
| 87 | +}; |
| 88 | + |
| 89 | +/* Common nested types */ |
| 90 | +/* ============== RTM_NEWADDR ============== */ |
| 91 | +/* RTM_NEWADDR - do */ |
| 92 | +int rt_addr_newaddr(ynl_cpp::ynl_socket& ys, rt_addr_newaddr_req& req) |
| 93 | +{ |
| 94 | + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; |
| 95 | + struct nlmsghdr *nlh; |
| 96 | + size_t hdr_len; |
| 97 | + void *hdr; |
| 98 | + int err; |
| 99 | + |
| 100 | + nlh = ynl_gemsg_start_req(ys, ((struct ynl_sock*)ys)->family_id, RTM_NEWADDR, 1); |
| 101 | + ((struct ynl_sock*)ys)->req_policy = &rt_addr_addr_attrs_nest; |
| 102 | + |
| 103 | + hdr_len = sizeof(req._hdr); |
| 104 | + hdr = ynl_nlmsg_put_extra_header(nlh, hdr_len); |
| 105 | + memcpy(hdr, &req._hdr, hdr_len); |
| 106 | + |
| 107 | + if (req.address.size() > 0) |
| 108 | + ynl_attr_put(nlh, IFA_ADDRESS, req.address.data(), req.address.size()); |
| 109 | + if (req.label.size() > 0) |
| 110 | + ynl_attr_put_str(nlh, IFA_LABEL, req.label.data()); |
| 111 | + if (req.local.size() > 0) |
| 112 | + ynl_attr_put(nlh, IFA_LOCAL, req.local.data(), req.local.size()); |
| 113 | + if (req.cacheinfo.size() > 0) |
| 114 | + ynl_attr_put(nlh, IFA_CACHEINFO, req.cacheinfo.data(), req.cacheinfo.size()); |
| 115 | + |
| 116 | + err = ynl_exec(ys, nlh, &yrs); |
| 117 | + if (err < 0) |
| 118 | + return -1; |
| 119 | + |
| 120 | + return 0; |
| 121 | +} |
| 122 | + |
| 123 | +/* ============== RTM_DELADDR ============== */ |
| 124 | +/* RTM_DELADDR - do */ |
| 125 | +int rt_addr_deladdr(ynl_cpp::ynl_socket& ys, rt_addr_deladdr_req& req) |
| 126 | +{ |
| 127 | + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; |
| 128 | + struct nlmsghdr *nlh; |
| 129 | + size_t hdr_len; |
| 130 | + void *hdr; |
| 131 | + int err; |
| 132 | + |
| 133 | + nlh = ynl_gemsg_start_req(ys, ((struct ynl_sock*)ys)->family_id, RTM_DELADDR, 1); |
| 134 | + ((struct ynl_sock*)ys)->req_policy = &rt_addr_addr_attrs_nest; |
| 135 | + |
| 136 | + hdr_len = sizeof(req._hdr); |
| 137 | + hdr = ynl_nlmsg_put_extra_header(nlh, hdr_len); |
| 138 | + memcpy(hdr, &req._hdr, hdr_len); |
| 139 | + |
| 140 | + if (req.address.size() > 0) |
| 141 | + ynl_attr_put(nlh, IFA_ADDRESS, req.address.data(), req.address.size()); |
| 142 | + if (req.local.size() > 0) |
| 143 | + ynl_attr_put(nlh, IFA_LOCAL, req.local.data(), req.local.size()); |
| 144 | + |
| 145 | + err = ynl_exec(ys, nlh, &yrs); |
| 146 | + if (err < 0) |
| 147 | + return -1; |
| 148 | + |
| 149 | + return 0; |
| 150 | +} |
| 151 | + |
| 152 | +/* ============== RTM_GETADDR ============== */ |
| 153 | +/* RTM_GETADDR - dump */ |
| 154 | +int rt_addr_getaddr_rsp_dump_parse(const struct nlmsghdr *nlh, |
| 155 | + struct ynl_parse_arg *yarg) |
| 156 | +{ |
| 157 | + rt_addr_getaddr_rsp_dump *dst; |
| 158 | + const struct nlattr *attr; |
| 159 | + void *hdr; |
| 160 | + |
| 161 | + dst = (rt_addr_getaddr_rsp_dump*)yarg->data; |
| 162 | + |
| 163 | + hdr = ynl_nlmsg_data_offset(nlh, sizeof(struct genlmsghdr)); |
| 164 | + memcpy(&dst->_hdr, hdr, sizeof(struct ifaddrmsg)); |
| 165 | + |
| 166 | + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { |
| 167 | + unsigned int type = ynl_attr_type(attr); |
| 168 | + |
| 169 | + if (type == IFA_ADDRESS) { |
| 170 | + if (ynl_attr_validate(yarg, attr)) |
| 171 | + return YNL_PARSE_CB_ERROR; |
| 172 | + unsigned int len = ynl_attr_data_len(attr); |
| 173 | + __u8 *data = (__u8*)ynl_attr_data(attr); |
| 174 | + dst->address.assign(data, data + len); |
| 175 | + } else if (type == IFA_LABEL) { |
| 176 | + if (ynl_attr_validate(yarg, attr)) |
| 177 | + return YNL_PARSE_CB_ERROR; |
| 178 | + dst->label.assign(ynl_attr_get_str(attr)); |
| 179 | + } else if (type == IFA_LOCAL) { |
| 180 | + if (ynl_attr_validate(yarg, attr)) |
| 181 | + return YNL_PARSE_CB_ERROR; |
| 182 | + unsigned int len = ynl_attr_data_len(attr); |
| 183 | + __u8 *data = (__u8*)ynl_attr_data(attr); |
| 184 | + dst->local.assign(data, data + len); |
| 185 | + } else if (type == IFA_CACHEINFO) { |
| 186 | + if (ynl_attr_validate(yarg, attr)) |
| 187 | + return YNL_PARSE_CB_ERROR; |
| 188 | + unsigned int len = ynl_attr_data_len(attr); |
| 189 | + __u8 *data = (__u8*)ynl_attr_data(attr); |
| 190 | + dst->cacheinfo.assign(data, data + len); |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + return YNL_PARSE_CB_OK; |
| 195 | +} |
| 196 | + |
| 197 | +std::unique_ptr<rt_addr_getaddr_rsp_list> |
| 198 | +rt_addr_getaddr_dump(ynl_cpp::ynl_socket& ys, rt_addr_getaddr_req_dump& req) |
| 199 | +{ |
| 200 | + struct ynl_dump_no_alloc_state yds = {}; |
| 201 | + struct nlmsghdr *nlh; |
| 202 | + size_t hdr_len; |
| 203 | + void *hdr; |
| 204 | + int err; |
| 205 | + |
| 206 | + auto ret = std::make_unique<rt_addr_getaddr_rsp_list>(); |
| 207 | + yds.yarg.ys = ys; |
| 208 | + yds.yarg.rsp_policy = &rt_addr_addr_attrs_nest; |
| 209 | + yds.yarg.data = ret.get(); |
| 210 | + yds.alloc_cb = [](void* arg)->void*{return &(static_cast<rt_addr_getaddr_rsp_list*>(arg)->objs.emplace_back());}; |
| 211 | + yds.cb = rt_addr_getaddr_rsp_dump_parse; |
| 212 | + yds.rsp_cmd = 20; |
| 213 | + |
| 214 | + nlh = ynl_gemsg_start_dump(ys, ((struct ynl_sock*)ys)->family_id, RTM_GETADDR, 1); |
| 215 | + hdr_len = sizeof(req._hdr); |
| 216 | + hdr = ynl_nlmsg_put_extra_header(nlh, hdr_len); |
| 217 | + memcpy(hdr, &req._hdr, hdr_len); |
| 218 | + |
| 219 | + ((struct ynl_sock*)ys)->req_policy = &rt_addr_addr_attrs_nest; |
| 220 | + |
| 221 | + err = ynl_exec_dump_no_alloc(ys, nlh, &yds); |
| 222 | + if (err < 0) |
| 223 | + return nullptr; |
| 224 | + |
| 225 | + return ret; |
| 226 | +} |
| 227 | + |
| 228 | +/* ============== RTM_GETMULTICAST ============== */ |
| 229 | +/* RTM_GETMULTICAST - do */ |
| 230 | +int rt_addr_getmulticast_rsp_parse(const struct nlmsghdr *nlh, |
| 231 | + struct ynl_parse_arg *yarg) |
| 232 | +{ |
| 233 | + rt_addr_getmulticast_rsp *dst; |
| 234 | + const struct nlattr *attr; |
| 235 | + void *hdr; |
| 236 | + |
| 237 | + dst = (rt_addr_getmulticast_rsp*)yarg->data; |
| 238 | + |
| 239 | + hdr = ynl_nlmsg_data_offset(nlh, sizeof(struct genlmsghdr)); |
| 240 | + memcpy(&dst->_hdr, hdr, sizeof(struct ifaddrmsg)); |
| 241 | + |
| 242 | + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { |
| 243 | + unsigned int type = ynl_attr_type(attr); |
| 244 | + |
| 245 | + if (type == IFA_MULTICAST) { |
| 246 | + if (ynl_attr_validate(yarg, attr)) |
| 247 | + return YNL_PARSE_CB_ERROR; |
| 248 | + unsigned int len = ynl_attr_data_len(attr); |
| 249 | + __u8 *data = (__u8*)ynl_attr_data(attr); |
| 250 | + dst->multicast.assign(data, data + len); |
| 251 | + } else if (type == IFA_CACHEINFO) { |
| 252 | + if (ynl_attr_validate(yarg, attr)) |
| 253 | + return YNL_PARSE_CB_ERROR; |
| 254 | + unsigned int len = ynl_attr_data_len(attr); |
| 255 | + __u8 *data = (__u8*)ynl_attr_data(attr); |
| 256 | + dst->cacheinfo.assign(data, data + len); |
| 257 | + } |
| 258 | + } |
| 259 | + |
| 260 | + return YNL_PARSE_CB_OK; |
| 261 | +} |
| 262 | + |
| 263 | +std::unique_ptr<rt_addr_getmulticast_rsp> |
| 264 | +rt_addr_getmulticast(ynl_cpp::ynl_socket& ys, rt_addr_getmulticast_req& req) |
| 265 | +{ |
| 266 | + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; |
| 267 | + std::unique_ptr<rt_addr_getmulticast_rsp> rsp; |
| 268 | + struct nlmsghdr *nlh; |
| 269 | + size_t hdr_len; |
| 270 | + void *hdr; |
| 271 | + int err; |
| 272 | + |
| 273 | + nlh = ynl_gemsg_start_req(ys, ((struct ynl_sock*)ys)->family_id, RTM_GETMULTICAST, 1); |
| 274 | + ((struct ynl_sock*)ys)->req_policy = &rt_addr_addr_attrs_nest; |
| 275 | + yrs.yarg.rsp_policy = &rt_addr_addr_attrs_nest; |
| 276 | + |
| 277 | + hdr_len = sizeof(req._hdr); |
| 278 | + hdr = ynl_nlmsg_put_extra_header(nlh, hdr_len); |
| 279 | + memcpy(hdr, &req._hdr, hdr_len); |
| 280 | + |
| 281 | + rsp.reset(new rt_addr_getmulticast_rsp()); |
| 282 | + yrs.yarg.data = rsp.get(); |
| 283 | + yrs.cb = rt_addr_getmulticast_rsp_parse; |
| 284 | + yrs.rsp_cmd = RTM_GETMULTICAST; |
| 285 | + |
| 286 | + err = ynl_exec(ys, nlh, &yrs); |
| 287 | + if (err < 0) |
| 288 | + return nullptr; |
| 289 | + |
| 290 | + return rsp; |
| 291 | +} |
| 292 | + |
| 293 | +/* RTM_GETMULTICAST - dump */ |
| 294 | +std::unique_ptr<rt_addr_getmulticast_list> |
| 295 | +rt_addr_getmulticast_dump(ynl_cpp::ynl_socket& ys, |
| 296 | + rt_addr_getmulticast_req_dump& req) |
| 297 | +{ |
| 298 | + struct ynl_dump_no_alloc_state yds = {}; |
| 299 | + struct nlmsghdr *nlh; |
| 300 | + size_t hdr_len; |
| 301 | + void *hdr; |
| 302 | + int err; |
| 303 | + |
| 304 | + auto ret = std::make_unique<rt_addr_getmulticast_list>(); |
| 305 | + yds.yarg.ys = ys; |
| 306 | + yds.yarg.rsp_policy = &rt_addr_addr_attrs_nest; |
| 307 | + yds.yarg.data = ret.get(); |
| 308 | + yds.alloc_cb = [](void* arg)->void*{return &(static_cast<rt_addr_getmulticast_list*>(arg)->objs.emplace_back());}; |
| 309 | + yds.cb = rt_addr_getmulticast_rsp_parse; |
| 310 | + yds.rsp_cmd = RTM_GETMULTICAST; |
| 311 | + |
| 312 | + nlh = ynl_gemsg_start_dump(ys, ((struct ynl_sock*)ys)->family_id, RTM_GETMULTICAST, 1); |
| 313 | + hdr_len = sizeof(req._hdr); |
| 314 | + hdr = ynl_nlmsg_put_extra_header(nlh, hdr_len); |
| 315 | + memcpy(hdr, &req._hdr, hdr_len); |
| 316 | + |
| 317 | + ((struct ynl_sock*)ys)->req_policy = &rt_addr_addr_attrs_nest; |
| 318 | + |
| 319 | + err = ynl_exec_dump_no_alloc(ys, nlh, &yds); |
| 320 | + if (err < 0) |
| 321 | + return nullptr; |
| 322 | + |
| 323 | + return ret; |
| 324 | +} |
| 325 | + |
| 326 | +const struct ynl_family ynl_rt_addr_family = { |
| 327 | + .name = "rt_addr", |
| 328 | + .hdr_len = sizeof(struct genlmsghdr) + sizeof(struct ifaddrmsg), |
| 329 | +}; |
| 330 | +const struct ynl_family& get_ynl_rt_addr_family() { |
| 331 | + return ynl_rt_addr_family; |
| 332 | +}; |
| 333 | +} //namespace ynl_cpp |
0 commit comments