diff --git a/home/nipa/nipa_out/850643/ynl/new-code/ovpn-user.c b/home/nipa/nipa_out/850643/ynl/new-code/ovpn-user.c new file mode 100644 index 000000000000..a80324c2163d --- /dev/null +++ b/home/nipa/nipa_out/850643/ynl/new-code/ovpn-user.c @@ -0,0 +1,844 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/ovpn.yaml */ +/* YNL-GEN user source */ + +#include +#include +#include "ovpn-user.h" +#include "ynl.h" +#include + +#include + +/* Enums */ +static const char * const ovpn_op_strmap[] = { + [OVPN_CMD_NEW_IFACE] = "new_iface", + [OVPN_CMD_DEL_IFACE] = "del_iface", + [OVPN_CMD_SET_PEER] = "set_peer", + [OVPN_CMD_GET_PEER] = "get_peer", + [OVPN_CMD_DEL_PEER] = "del_peer", + [OVPN_CMD_SET_KEY] = "set_key", + [OVPN_CMD_SWAP_KEYS] = "swap_keys", + [OVPN_CMD_DEL_KEY] = "del_key", +}; + +const char *ovpn_op_str(int op) +{ + if (op < 0 || op >= (int)YNL_ARRAY_SIZE(ovpn_op_strmap)) + return NULL; + return ovpn_op_strmap[op]; +} + +static const char * const ovpn_cipher_alg_strmap[] = { + [0] = "none", + [1] = "aes_gcm", + [2] = "chacha20_poly1305", +}; + +const char *ovpn_cipher_alg_str(enum ovpn_cipher_alg value) +{ + if (value < 0 || value >= (int)YNL_ARRAY_SIZE(ovpn_cipher_alg_strmap)) + return NULL; + return ovpn_cipher_alg_strmap[value]; +} + +static const char * const ovpn_del_peer_reason_strmap[] = { + [0] = "teardown", + [1] = "userspace", + [2] = "expired", + [3] = "transport_error", + [4] = "transport_disconnect", +}; + +const char *ovpn_del_peer_reason_str(enum ovpn_del_peer_reason value) +{ + if (value < 0 || value >= (int)YNL_ARRAY_SIZE(ovpn_del_peer_reason_strmap)) + return NULL; + return ovpn_del_peer_reason_strmap[value]; +} + +static const char * const ovpn_key_slot_strmap[] = { + [0] = "primary", + [1] = "secondary", +}; + +const char *ovpn_key_slot_str(enum ovpn_key_slot value) +{ + if (value < 0 || value >= (int)YNL_ARRAY_SIZE(ovpn_key_slot_strmap)) + return NULL; + return ovpn_key_slot_strmap[value]; +} + +static const char * const ovpn_mode_strmap[] = { + [0] = "p2p", + [1] = "mp", +}; + +const char *ovpn_mode_str(enum ovpn_mode value) +{ + if (value < 0 || value >= (int)YNL_ARRAY_SIZE(ovpn_mode_strmap)) + return NULL; + return ovpn_mode_strmap[value]; +} + +/* Policies */ +struct ynl_policy_attr ovpn_keydir_policy[OVPN_A_KEYDIR_MAX + 1] = { + [OVPN_A_KEYDIR_CIPHER_KEY] = { .name = "cipher_key", .type = YNL_PT_BINARY,}, + [OVPN_A_KEYDIR_NONCE_TAIL] = { .name = "nonce_tail", .type = YNL_PT_BINARY,}, +}; + +struct ynl_policy_nest ovpn_keydir_nest = { + .max_attr = OVPN_A_KEYDIR_MAX, + .table = ovpn_keydir_policy, +}; + +struct ynl_policy_attr ovpn_keyconf_policy[OVPN_A_KEYCONF_MAX + 1] = { + [OVPN_A_KEYCONF_SLOT] = { .name = "slot", .type = YNL_PT_U32, }, + [OVPN_A_KEYCONF_KEY_ID] = { .name = "key_id", .type = YNL_PT_U32, }, + [OVPN_A_KEYCONF_CIPHER_ALG] = { .name = "cipher_alg", .type = YNL_PT_U32, }, + [OVPN_A_KEYCONF_ENCRYPT_DIR] = { .name = "encrypt_dir", .type = YNL_PT_NEST, .nest = &ovpn_keydir_nest, }, + [OVPN_A_KEYCONF_DECRYPT_DIR] = { .name = "decrypt_dir", .type = YNL_PT_NEST, .nest = &ovpn_keydir_nest, }, +}; + +struct ynl_policy_nest ovpn_keyconf_nest = { + .max_attr = OVPN_A_KEYCONF_MAX, + .table = ovpn_keyconf_policy, +}; + +struct ynl_policy_attr ovpn_peer_policy[OVPN_A_PEER_MAX + 1] = { + [OVPN_A_PEER_ID] = { .name = "id", .type = YNL_PT_U32, }, + [OVPN_A_PEER_SOCKADDR_REMOTE] = { .name = "sockaddr_remote", .type = YNL_PT_BINARY,}, + [OVPN_A_PEER_SOCKET] = { .name = "socket", .type = YNL_PT_U32, }, + [OVPN_A_PEER_VPN_IPV4] = { .name = "vpn_ipv4", .type = YNL_PT_U32, }, + [OVPN_A_PEER_VPN_IPV6] = { .name = "vpn_ipv6", .type = YNL_PT_BINARY,}, + [OVPN_A_PEER_LOCAL_IP] = { .name = "local_ip", .type = YNL_PT_BINARY,}, + [OVPN_A_PEER_LOCAL_PORT] = { .name = "local_port", .type = YNL_PT_U32, }, + [OVPN_A_PEER_KEEPALIVE_INTERVAL] = { .name = "keepalive_interval", .type = YNL_PT_U32, }, + [OVPN_A_PEER_KEEPALIVE_TIMEOUT] = { .name = "keepalive_timeout", .type = YNL_PT_U32, }, + [OVPN_A_PEER_DEL_REASON] = { .name = "del_reason", .type = YNL_PT_U32, }, + [OVPN_A_PEER_KEYCONF] = { .name = "keyconf", .type = YNL_PT_NEST, .nest = &ovpn_keyconf_nest, }, + [OVPN_A_PEER_VPN_RX_BYTES] = { .name = "vpn_rx_bytes", .type = YNL_PT_UINT, }, + [OVPN_A_PEER_VPN_TX_BYTES] = { .name = "vpn_tx_bytes", .type = YNL_PT_UINT, }, + [OVPN_A_PEER_VPN_RX_PACKETS] = { .name = "vpn_rx_packets", .type = YNL_PT_U32, }, + [OVPN_A_PEER_VPN_TX_PACKETS] = { .name = "vpn_tx_packets", .type = YNL_PT_U32, }, + [OVPN_A_PEER_LINK_RX_BYTES] = { .name = "link_rx_bytes", .type = YNL_PT_UINT, }, + [OVPN_A_PEER_LINK_TX_BYTES] = { .name = "link_tx_bytes", .type = YNL_PT_UINT, }, + [OVPN_A_PEER_LINK_RX_PACKETS] = { .name = "link_rx_packets", .type = YNL_PT_U32, }, + [OVPN_A_PEER_LINK_TX_PACKETS] = { .name = "link_tx_packets", .type = YNL_PT_U32, }, +}; + +struct ynl_policy_nest ovpn_peer_nest = { + .max_attr = OVPN_A_PEER_MAX, + .table = ovpn_peer_policy, +}; + +struct ynl_policy_attr ovpn_policy[OVPN_A_MAX + 1] = { + [OVPN_A_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, + [OVPN_A_IFNAME] = { .name = "ifname", .type = YNL_PT_NUL_STR, }, + [OVPN_A_MODE] = { .name = "mode", .type = YNL_PT_U32, }, + [OVPN_A_PEER] = { .name = "peer", .type = YNL_PT_NEST, .nest = &ovpn_peer_nest, }, + [OVPN_A_PAD] = { .name = "pad", .type = YNL_PT_IGNORE, }, +}; + +struct ynl_policy_nest ovpn_nest = { + .max_attr = OVPN_A_MAX, + .table = ovpn_policy, +}; + +/* Common nested types */ +void ovpn_keydir_free(struct ovpn_keydir *obj) +{ + free(obj->cipher_key); + free(obj->nonce_tail); +} + +int ovpn_keydir_put(struct nlmsghdr *nlh, unsigned int attr_type, + struct ovpn_keydir *obj) +{ + struct nlattr *nest; + + nest = ynl_attr_nest_start(nlh, attr_type); + if (obj->_present.cipher_key_len) + ynl_attr_put(nlh, OVPN_A_KEYDIR_CIPHER_KEY, obj->cipher_key, obj->_present.cipher_key_len); + if (obj->_present.nonce_tail_len) + ynl_attr_put(nlh, OVPN_A_KEYDIR_NONCE_TAIL, obj->nonce_tail, obj->_present.nonce_tail_len); + ynl_attr_nest_end(nlh, nest); + + return 0; +} + +int ovpn_keydir_parse(struct ynl_parse_arg *yarg, const struct nlattr *nested) +{ + struct ovpn_keydir *dst = yarg->data; + const struct nlattr *attr; + + ynl_attr_for_each_nested(attr, nested) { + unsigned int type = ynl_attr_type(attr); + + if (type == OVPN_A_KEYDIR_CIPHER_KEY) { + unsigned int len; + + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + + len = ynl_attr_data_len(attr); + dst->_present.cipher_key_len = len; + dst->cipher_key = malloc(len); + memcpy(dst->cipher_key, ynl_attr_data(attr), len); + } else if (type == OVPN_A_KEYDIR_NONCE_TAIL) { + unsigned int len; + + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + + len = ynl_attr_data_len(attr); + dst->_present.nonce_tail_len = len; + dst->nonce_tail = malloc(len); + memcpy(dst->nonce_tail, ynl_attr_data(attr), len); + } + } + + return 0; +} + +void ovpn_keyconf_free(struct ovpn_keyconf *obj) +{ + ovpn_keydir_free(&obj->encrypt_dir); + ovpn_keydir_free(&obj->decrypt_dir); +} + +int ovpn_keyconf_put(struct nlmsghdr *nlh, unsigned int attr_type, + struct ovpn_keyconf *obj) +{ + struct nlattr *nest; + + nest = ynl_attr_nest_start(nlh, attr_type); + if (obj->_present.slot) + ynl_attr_put_u32(nlh, OVPN_A_KEYCONF_SLOT, obj->slot); + if (obj->_present.key_id) + ynl_attr_put_u32(nlh, OVPN_A_KEYCONF_KEY_ID, obj->key_id); + if (obj->_present.cipher_alg) + ynl_attr_put_u32(nlh, OVPN_A_KEYCONF_CIPHER_ALG, obj->cipher_alg); + if (obj->_present.encrypt_dir) + ovpn_keydir_put(nlh, OVPN_A_KEYCONF_ENCRYPT_DIR, &obj->encrypt_dir); + if (obj->_present.decrypt_dir) + ovpn_keydir_put(nlh, OVPN_A_KEYCONF_DECRYPT_DIR, &obj->decrypt_dir); + ynl_attr_nest_end(nlh, nest); + + return 0; +} + +int ovpn_keyconf_parse(struct ynl_parse_arg *yarg, const struct nlattr *nested) +{ + struct ovpn_keyconf *dst = yarg->data; + const struct nlattr *attr; + struct ynl_parse_arg parg; + + parg.ys = yarg->ys; + + ynl_attr_for_each_nested(attr, nested) { + unsigned int type = ynl_attr_type(attr); + + if (type == OVPN_A_KEYCONF_SLOT) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.slot = 1; + dst->slot = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_KEYCONF_KEY_ID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.key_id = 1; + dst->key_id = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_KEYCONF_CIPHER_ALG) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.cipher_alg = 1; + dst->cipher_alg = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_KEYCONF_ENCRYPT_DIR) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.encrypt_dir = 1; + + parg.rsp_policy = &ovpn_keydir_nest; + parg.data = &dst->encrypt_dir; + if (ovpn_keydir_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } else if (type == OVPN_A_KEYCONF_DECRYPT_DIR) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.decrypt_dir = 1; + + parg.rsp_policy = &ovpn_keydir_nest; + parg.data = &dst->decrypt_dir; + if (ovpn_keydir_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } + } + + return 0; +} + +void ovpn_peer_free(struct ovpn_peer *obj) +{ + free(obj->sockaddr_remote); + free(obj->vpn_ipv6); + free(obj->local_ip); + ovpn_keyconf_free(&obj->keyconf); +} + +int ovpn_peer_put(struct nlmsghdr *nlh, unsigned int attr_type, + struct ovpn_peer *obj) +{ + struct nlattr *nest; + + nest = ynl_attr_nest_start(nlh, attr_type); + if (obj->_present.id) + ynl_attr_put_u32(nlh, OVPN_A_PEER_ID, obj->id); + if (obj->_present.sockaddr_remote_len) + ynl_attr_put(nlh, OVPN_A_PEER_SOCKADDR_REMOTE, obj->sockaddr_remote, obj->_present.sockaddr_remote_len); + if (obj->_present.socket) + ynl_attr_put_u32(nlh, OVPN_A_PEER_SOCKET, obj->socket); + if (obj->_present.vpn_ipv4) + ynl_attr_put_u32(nlh, OVPN_A_PEER_VPN_IPV4, obj->vpn_ipv4); + if (obj->_present.vpn_ipv6_len) + ynl_attr_put(nlh, OVPN_A_PEER_VPN_IPV6, obj->vpn_ipv6, obj->_present.vpn_ipv6_len); + if (obj->_present.local_ip_len) + ynl_attr_put(nlh, OVPN_A_PEER_LOCAL_IP, obj->local_ip, obj->_present.local_ip_len); + if (obj->_present.local_port) + ynl_attr_put_u32(nlh, OVPN_A_PEER_LOCAL_PORT, obj->local_port); + if (obj->_present.keepalive_interval) + ynl_attr_put_u32(nlh, OVPN_A_PEER_KEEPALIVE_INTERVAL, obj->keepalive_interval); + if (obj->_present.keepalive_timeout) + ynl_attr_put_u32(nlh, OVPN_A_PEER_KEEPALIVE_TIMEOUT, obj->keepalive_timeout); + if (obj->_present.del_reason) + ynl_attr_put_u32(nlh, OVPN_A_PEER_DEL_REASON, obj->del_reason); + if (obj->_present.keyconf) + ovpn_keyconf_put(nlh, OVPN_A_PEER_KEYCONF, &obj->keyconf); + if (obj->_present.vpn_rx_bytes) + ynl_attr_put_uint(nlh, OVPN_A_PEER_VPN_RX_BYTES, obj->vpn_rx_bytes); + if (obj->_present.vpn_tx_bytes) + ynl_attr_put_uint(nlh, OVPN_A_PEER_VPN_TX_BYTES, obj->vpn_tx_bytes); + if (obj->_present.vpn_rx_packets) + ynl_attr_put_u32(nlh, OVPN_A_PEER_VPN_RX_PACKETS, obj->vpn_rx_packets); + if (obj->_present.vpn_tx_packets) + ynl_attr_put_u32(nlh, OVPN_A_PEER_VPN_TX_PACKETS, obj->vpn_tx_packets); + if (obj->_present.link_rx_bytes) + ynl_attr_put_uint(nlh, OVPN_A_PEER_LINK_RX_BYTES, obj->link_rx_bytes); + if (obj->_present.link_tx_bytes) + ynl_attr_put_uint(nlh, OVPN_A_PEER_LINK_TX_BYTES, obj->link_tx_bytes); + if (obj->_present.link_rx_packets) + ynl_attr_put_u32(nlh, OVPN_A_PEER_LINK_RX_PACKETS, obj->link_rx_packets); + if (obj->_present.link_tx_packets) + ynl_attr_put_u32(nlh, OVPN_A_PEER_LINK_TX_PACKETS, obj->link_tx_packets); + ynl_attr_nest_end(nlh, nest); + + return 0; +} + +int ovpn_peer_parse(struct ynl_parse_arg *yarg, const struct nlattr *nested) +{ + struct ovpn_peer *dst = yarg->data; + const struct nlattr *attr; + struct ynl_parse_arg parg; + + parg.ys = yarg->ys; + + ynl_attr_for_each_nested(attr, nested) { + unsigned int type = ynl_attr_type(attr); + + if (type == OVPN_A_PEER_ID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.id = 1; + dst->id = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_PEER_SOCKADDR_REMOTE) { + unsigned int len; + + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + + len = ynl_attr_data_len(attr); + dst->_present.sockaddr_remote_len = len; + dst->sockaddr_remote = malloc(len); + memcpy(dst->sockaddr_remote, ynl_attr_data(attr), len); + } else if (type == OVPN_A_PEER_SOCKET) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.socket = 1; + dst->socket = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_PEER_VPN_IPV4) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.vpn_ipv4 = 1; + dst->vpn_ipv4 = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_PEER_VPN_IPV6) { + unsigned int len; + + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + + len = ynl_attr_data_len(attr); + dst->_present.vpn_ipv6_len = len; + dst->vpn_ipv6 = malloc(len); + memcpy(dst->vpn_ipv6, ynl_attr_data(attr), len); + } else if (type == OVPN_A_PEER_LOCAL_IP) { + unsigned int len; + + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + + len = ynl_attr_data_len(attr); + dst->_present.local_ip_len = len; + dst->local_ip = malloc(len); + memcpy(dst->local_ip, ynl_attr_data(attr), len); + } else if (type == OVPN_A_PEER_LOCAL_PORT) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.local_port = 1; + dst->local_port = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_PEER_KEEPALIVE_INTERVAL) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.keepalive_interval = 1; + dst->keepalive_interval = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_PEER_KEEPALIVE_TIMEOUT) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.keepalive_timeout = 1; + dst->keepalive_timeout = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_PEER_DEL_REASON) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.del_reason = 1; + dst->del_reason = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_PEER_KEYCONF) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.keyconf = 1; + + parg.rsp_policy = &ovpn_keyconf_nest; + parg.data = &dst->keyconf; + if (ovpn_keyconf_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } else if (type == OVPN_A_PEER_VPN_RX_BYTES) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.vpn_rx_bytes = 1; + dst->vpn_rx_bytes = ynl_attr_get_uint(attr); + } else if (type == OVPN_A_PEER_VPN_TX_BYTES) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.vpn_tx_bytes = 1; + dst->vpn_tx_bytes = ynl_attr_get_uint(attr); + } else if (type == OVPN_A_PEER_VPN_RX_PACKETS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.vpn_rx_packets = 1; + dst->vpn_rx_packets = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_PEER_VPN_TX_PACKETS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.vpn_tx_packets = 1; + dst->vpn_tx_packets = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_PEER_LINK_RX_BYTES) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.link_rx_bytes = 1; + dst->link_rx_bytes = ynl_attr_get_uint(attr); + } else if (type == OVPN_A_PEER_LINK_TX_BYTES) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.link_tx_bytes = 1; + dst->link_tx_bytes = ynl_attr_get_uint(attr); + } else if (type == OVPN_A_PEER_LINK_RX_PACKETS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.link_rx_packets = 1; + dst->link_rx_packets = ynl_attr_get_u32(attr); + } else if (type == OVPN_A_PEER_LINK_TX_PACKETS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.link_tx_packets = 1; + dst->link_tx_packets = ynl_attr_get_u32(attr); + } + } + + return 0; +} + +/* ============== OVPN_CMD_NEW_IFACE ============== */ +/* OVPN_CMD_NEW_IFACE - do */ +void ovpn_new_iface_req_free(struct ovpn_new_iface_req *req) +{ + free(req->ifname); + free(req); +} + +void ovpn_new_iface_rsp_free(struct ovpn_new_iface_rsp *rsp) +{ + free(rsp->ifname); + free(rsp); +} + +int ovpn_new_iface_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct ovpn_new_iface_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == OVPN_A_IFNAME) { + unsigned int len; + + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + + len = strnlen(ynl_attr_get_str(attr), ynl_attr_data_len(attr)); + dst->_present.ifname_len = len; + dst->ifname = malloc(len + 1); + memcpy(dst->ifname, ynl_attr_get_str(attr), len); + dst->ifname[len] = 0; + } + } + + return YNL_PARSE_CB_OK; +} + +struct ovpn_new_iface_rsp * +ovpn_new_iface(struct ynl_sock *ys, struct ovpn_new_iface_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct ovpn_new_iface_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, OVPN_CMD_NEW_IFACE, 1); + ys->req_policy = &ovpn_nest; + yrs.yarg.rsp_policy = &ovpn_nest; + + if (req->_present.ifname_len) + ynl_attr_put_str(nlh, OVPN_A_IFNAME, req->ifname); + if (req->_present.mode) + ynl_attr_put_u32(nlh, OVPN_A_MODE, req->mode); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = ovpn_new_iface_rsp_parse; + yrs.rsp_cmd = OVPN_CMD_NEW_IFACE; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + ovpn_new_iface_rsp_free(rsp); + return NULL; +} + +/* ============== OVPN_CMD_DEL_IFACE ============== */ +/* OVPN_CMD_DEL_IFACE - do */ +void ovpn_del_iface_req_free(struct ovpn_del_iface_req *req) +{ + free(req); +} + +int ovpn_del_iface(struct ynl_sock *ys, struct ovpn_del_iface_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, OVPN_CMD_DEL_IFACE, 1); + ys->req_policy = &ovpn_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, OVPN_A_IFINDEX, req->ifindex); + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + return -1; + + return 0; +} + +/* ============== OVPN_CMD_SET_PEER ============== */ +/* OVPN_CMD_SET_PEER - do */ +void ovpn_set_peer_req_free(struct ovpn_set_peer_req *req) +{ + ovpn_peer_free(&req->peer); + free(req); +} + +int ovpn_set_peer(struct ynl_sock *ys, struct ovpn_set_peer_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, OVPN_CMD_SET_PEER, 1); + ys->req_policy = &ovpn_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, OVPN_A_IFINDEX, req->ifindex); + if (req->_present.peer) + ovpn_peer_put(nlh, OVPN_A_PEER, &req->peer); + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + return -1; + + return 0; +} + +/* ============== OVPN_CMD_GET_PEER ============== */ +/* OVPN_CMD_GET_PEER - do */ +void ovpn_get_peer_req_free(struct ovpn_get_peer_req *req) +{ + ovpn_peer_free(&req->peer); + free(req); +} + +void ovpn_get_peer_rsp_free(struct ovpn_get_peer_rsp *rsp) +{ + ovpn_peer_free(&rsp->peer); + free(rsp); +} + +int ovpn_get_peer_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct ovpn_get_peer_rsp *dst; + const struct nlattr *attr; + struct ynl_parse_arg parg; + + dst = yarg->data; + parg.ys = yarg->ys; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == OVPN_A_PEER) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.peer = 1; + + parg.rsp_policy = &ovpn_peer_nest; + parg.data = &dst->peer; + if (ovpn_peer_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } + } + + return YNL_PARSE_CB_OK; +} + +struct ovpn_get_peer_rsp * +ovpn_get_peer(struct ynl_sock *ys, struct ovpn_get_peer_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct ovpn_get_peer_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, OVPN_CMD_GET_PEER, 1); + ys->req_policy = &ovpn_nest; + yrs.yarg.rsp_policy = &ovpn_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, OVPN_A_IFINDEX, req->ifindex); + if (req->_present.peer) + ovpn_peer_put(nlh, OVPN_A_PEER, &req->peer); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = ovpn_get_peer_rsp_parse; + yrs.rsp_cmd = OVPN_CMD_GET_PEER; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + ovpn_get_peer_rsp_free(rsp); + return NULL; +} + +/* OVPN_CMD_GET_PEER - dump */ +void ovpn_get_peer_req_dump_free(struct ovpn_get_peer_req_dump *req) +{ + free(req); +} + +void ovpn_get_peer_list_free(struct ovpn_get_peer_list *rsp) +{ + struct ovpn_get_peer_list *next = rsp; + + while ((void *)next != YNL_LIST_END) { + rsp = next; + next = rsp->next; + + ovpn_peer_free(&rsp->obj.peer); + free(rsp); + } +} + +struct ovpn_get_peer_list * +ovpn_get_peer_dump(struct ynl_sock *ys, struct ovpn_get_peer_req_dump *req) +{ + struct ynl_dump_state yds = {}; + struct nlmsghdr *nlh; + int err; + + yds.yarg.ys = ys; + yds.yarg.rsp_policy = &ovpn_nest; + yds.yarg.data = NULL; + yds.alloc_sz = sizeof(struct ovpn_get_peer_list); + yds.cb = ovpn_get_peer_rsp_parse; + yds.rsp_cmd = OVPN_CMD_GET_PEER; + + nlh = ynl_gemsg_start_dump(ys, ys->family_id, OVPN_CMD_GET_PEER, 1); + ys->req_policy = &ovpn_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, OVPN_A_IFINDEX, req->ifindex); + + err = ynl_exec_dump(ys, nlh, &yds); + if (err < 0) + goto free_list; + + return yds.first; + +free_list: + ovpn_get_peer_list_free(yds.first); + return NULL; +} + +/* ============== OVPN_CMD_DEL_PEER ============== */ +/* OVPN_CMD_DEL_PEER - do */ +void ovpn_del_peer_req_free(struct ovpn_del_peer_req *req) +{ + ovpn_peer_free(&req->peer); + free(req); +} + +int ovpn_del_peer(struct ynl_sock *ys, struct ovpn_del_peer_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, OVPN_CMD_DEL_PEER, 1); + ys->req_policy = &ovpn_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, OVPN_A_IFINDEX, req->ifindex); + if (req->_present.peer) + ovpn_peer_put(nlh, OVPN_A_PEER, &req->peer); + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + return -1; + + return 0; +} + +/* ============== OVPN_CMD_SET_KEY ============== */ +/* OVPN_CMD_SET_KEY - do */ +void ovpn_set_key_req_free(struct ovpn_set_key_req *req) +{ + ovpn_peer_free(&req->peer); + free(req); +} + +int ovpn_set_key(struct ynl_sock *ys, struct ovpn_set_key_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, OVPN_CMD_SET_KEY, 1); + ys->req_policy = &ovpn_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, OVPN_A_IFINDEX, req->ifindex); + if (req->_present.peer) + ovpn_peer_put(nlh, OVPN_A_PEER, &req->peer); + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + return -1; + + return 0; +} + +/* ============== OVPN_CMD_SWAP_KEYS ============== */ +/* OVPN_CMD_SWAP_KEYS - do */ +void ovpn_swap_keys_req_free(struct ovpn_swap_keys_req *req) +{ + ovpn_peer_free(&req->peer); + free(req); +} + +int ovpn_swap_keys(struct ynl_sock *ys, struct ovpn_swap_keys_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, OVPN_CMD_SWAP_KEYS, 1); + ys->req_policy = &ovpn_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, OVPN_A_IFINDEX, req->ifindex); + if (req->_present.peer) + ovpn_peer_put(nlh, OVPN_A_PEER, &req->peer); + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + return -1; + + return 0; +} + +/* ============== OVPN_CMD_DEL_KEY ============== */ +/* OVPN_CMD_DEL_KEY - do */ +void ovpn_del_key_req_free(struct ovpn_del_key_req *req) +{ + ovpn_peer_free(&req->peer); + free(req); +} + +int ovpn_del_key(struct ynl_sock *ys, struct ovpn_del_key_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, OVPN_CMD_DEL_KEY, 1); + ys->req_policy = &ovpn_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, OVPN_A_IFINDEX, req->ifindex); + if (req->_present.peer) + ovpn_peer_put(nlh, OVPN_A_PEER, &req->peer); + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + return -1; + + return 0; +} + +const struct ynl_family ynl_ovpn_family = { + .name = "ovpn", + .hdr_len = sizeof(struct genlmsghdr), +}; diff --git a/home/nipa/nipa_out/850643/ynl/new-code/ovpn-user.h b/home/nipa/nipa_out/850643/ynl/new-code/ovpn-user.h new file mode 100644 index 000000000000..f7f527506f3e --- /dev/null +++ b/home/nipa/nipa_out/850643/ynl/new-code/ovpn-user.h @@ -0,0 +1,1769 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/ovpn.yaml */ +/* YNL-GEN user header */ + +#ifndef _LINUX_OVPN_GEN_H +#define _LINUX_OVPN_GEN_H + +#include +#include +#include +#include + +struct ynl_sock; + +extern const struct ynl_family ynl_ovpn_family; + +/* Enums */ +const char *ovpn_op_str(int op); +const char *ovpn_cipher_alg_str(enum ovpn_cipher_alg value); +const char *ovpn_del_peer_reason_str(enum ovpn_del_peer_reason value); +const char *ovpn_key_slot_str(enum ovpn_key_slot value); +const char *ovpn_mode_str(enum ovpn_mode value); + +/* Common nested types */ +struct ovpn_keydir { + struct { + __u32 cipher_key_len; + __u32 nonce_tail_len; + } _present; + + void *cipher_key; + void *nonce_tail; +}; + +struct ovpn_keyconf { + struct { + __u32 slot:1; + __u32 key_id:1; + __u32 cipher_alg:1; + __u32 encrypt_dir:1; + __u32 decrypt_dir:1; + } _present; + + enum ovpn_key_slot slot; + __u32 key_id; + enum ovpn_cipher_alg cipher_alg; + struct ovpn_keydir encrypt_dir; + struct ovpn_keydir decrypt_dir; +}; + +struct ovpn_peer { + struct { + __u32 id:1; + __u32 sockaddr_remote_len; + __u32 socket:1; + __u32 vpn_ipv4:1; + __u32 vpn_ipv6_len; + __u32 local_ip_len; + __u32 local_port:1; + __u32 keepalive_interval:1; + __u32 keepalive_timeout:1; + __u32 del_reason:1; + __u32 keyconf:1; + __u32 vpn_rx_bytes:1; + __u32 vpn_tx_bytes:1; + __u32 vpn_rx_packets:1; + __u32 vpn_tx_packets:1; + __u32 link_rx_bytes:1; + __u32 link_tx_bytes:1; + __u32 link_rx_packets:1; + __u32 link_tx_packets:1; + } _present; + + __u32 id; + void *sockaddr_remote; + __u32 socket; + __u32 vpn_ipv4; + void *vpn_ipv6; + void *local_ip; + __u32 local_port; + __u32 keepalive_interval; + __u32 keepalive_timeout; + enum ovpn_del_peer_reason del_reason; + struct ovpn_keyconf keyconf; + __u64 vpn_rx_bytes; + __u64 vpn_tx_bytes; + __u32 vpn_rx_packets; + __u32 vpn_tx_packets; + __u64 link_rx_bytes; + __u64 link_tx_bytes; + __u32 link_rx_packets; + __u32 link_tx_packets; +}; + +/* ============== OVPN_CMD_NEW_IFACE ============== */ +/* OVPN_CMD_NEW_IFACE - do */ +struct ovpn_new_iface_req { + struct { + __u32 ifname_len; + __u32 mode:1; + } _present; + + char *ifname; + enum ovpn_mode mode; +}; + +static inline struct ovpn_new_iface_req *ovpn_new_iface_req_alloc(void) +{ + return calloc(1, sizeof(struct ovpn_new_iface_req)); +} +void ovpn_new_iface_req_free(struct ovpn_new_iface_req *req); + +static inline void +ovpn_new_iface_req_set_ifname(struct ovpn_new_iface_req *req, + const char *ifname) +{ + free(req->ifname); + req->_present.ifname_len = strlen(ifname); + req->ifname = malloc(req->_present.ifname_len + 1); + memcpy(req->ifname, ifname, req->_present.ifname_len); + req->ifname[req->_present.ifname_len] = 0; +} +static inline void +ovpn_new_iface_req_set_mode(struct ovpn_new_iface_req *req, + enum ovpn_mode mode) +{ + req->_present.mode = 1; + req->mode = mode; +} + +struct ovpn_new_iface_rsp { + struct { + __u32 ifname_len; + } _present; + + char *ifname; +}; + +void ovpn_new_iface_rsp_free(struct ovpn_new_iface_rsp *rsp); + +/* + * Create a new interface + */ +struct ovpn_new_iface_rsp * +ovpn_new_iface(struct ynl_sock *ys, struct ovpn_new_iface_req *req); + +/* ============== OVPN_CMD_DEL_IFACE ============== */ +/* OVPN_CMD_DEL_IFACE - do */ +struct ovpn_del_iface_req { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; +}; + +static inline struct ovpn_del_iface_req *ovpn_del_iface_req_alloc(void) +{ + return calloc(1, sizeof(struct ovpn_del_iface_req)); +} +void ovpn_del_iface_req_free(struct ovpn_del_iface_req *req); + +static inline void +ovpn_del_iface_req_set_ifindex(struct ovpn_del_iface_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} + +/* + * Delete existing interface + */ +int ovpn_del_iface(struct ynl_sock *ys, struct ovpn_del_iface_req *req); + +/* ============== OVPN_CMD_SET_PEER ============== */ +/* OVPN_CMD_SET_PEER - do */ +struct ovpn_set_peer_req { + struct { + __u32 ifindex:1; + __u32 peer:1; + } _present; + + __u32 ifindex; + struct ovpn_peer peer; +}; + +static inline struct ovpn_set_peer_req *ovpn_set_peer_req_alloc(void) +{ + return calloc(1, sizeof(struct ovpn_set_peer_req)); +} +void ovpn_set_peer_req_free(struct ovpn_set_peer_req *req); + +static inline void +ovpn_set_peer_req_set_ifindex(struct ovpn_set_peer_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +ovpn_set_peer_req_set_peer_id(struct ovpn_set_peer_req *req, __u32 id) +{ + req->_present.peer = 1; + req->peer._present.id = 1; + req->peer.id = id; +} +static inline void +ovpn_set_peer_req_set_peer_sockaddr_remote(struct ovpn_set_peer_req *req, + const void *sockaddr_remote, + size_t len) +{ + req->_present.peer = 1; + free(req->peer.sockaddr_remote); + req->peer._present.sockaddr_remote_len = len; + req->peer.sockaddr_remote = malloc(req->peer._present.sockaddr_remote_len); + memcpy(req->peer.sockaddr_remote, sockaddr_remote, req->peer._present.sockaddr_remote_len); +} +static inline void +ovpn_set_peer_req_set_peer_socket(struct ovpn_set_peer_req *req, __u32 socket) +{ + req->_present.peer = 1; + req->peer._present.socket = 1; + req->peer.socket = socket; +} +static inline void +ovpn_set_peer_req_set_peer_vpn_ipv4(struct ovpn_set_peer_req *req, + __u32 vpn_ipv4) +{ + req->_present.peer = 1; + req->peer._present.vpn_ipv4 = 1; + req->peer.vpn_ipv4 = vpn_ipv4; +} +static inline void +ovpn_set_peer_req_set_peer_vpn_ipv6(struct ovpn_set_peer_req *req, + const void *vpn_ipv6, size_t len) +{ + req->_present.peer = 1; + free(req->peer.vpn_ipv6); + req->peer._present.vpn_ipv6_len = len; + req->peer.vpn_ipv6 = malloc(req->peer._present.vpn_ipv6_len); + memcpy(req->peer.vpn_ipv6, vpn_ipv6, req->peer._present.vpn_ipv6_len); +} +static inline void +ovpn_set_peer_req_set_peer_local_ip(struct ovpn_set_peer_req *req, + const void *local_ip, size_t len) +{ + req->_present.peer = 1; + free(req->peer.local_ip); + req->peer._present.local_ip_len = len; + req->peer.local_ip = malloc(req->peer._present.local_ip_len); + memcpy(req->peer.local_ip, local_ip, req->peer._present.local_ip_len); +} +static inline void +ovpn_set_peer_req_set_peer_local_port(struct ovpn_set_peer_req *req, + __u32 local_port) +{ + req->_present.peer = 1; + req->peer._present.local_port = 1; + req->peer.local_port = local_port; +} +static inline void +ovpn_set_peer_req_set_peer_keepalive_interval(struct ovpn_set_peer_req *req, + __u32 keepalive_interval) +{ + req->_present.peer = 1; + req->peer._present.keepalive_interval = 1; + req->peer.keepalive_interval = keepalive_interval; +} +static inline void +ovpn_set_peer_req_set_peer_keepalive_timeout(struct ovpn_set_peer_req *req, + __u32 keepalive_timeout) +{ + req->_present.peer = 1; + req->peer._present.keepalive_timeout = 1; + req->peer.keepalive_timeout = keepalive_timeout; +} +static inline void +ovpn_set_peer_req_set_peer_del_reason(struct ovpn_set_peer_req *req, + enum ovpn_del_peer_reason del_reason) +{ + req->_present.peer = 1; + req->peer._present.del_reason = 1; + req->peer.del_reason = del_reason; +} +static inline void +ovpn_set_peer_req_set_peer_keyconf_slot(struct ovpn_set_peer_req *req, + enum ovpn_key_slot slot) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.slot = 1; + req->peer.keyconf.slot = slot; +} +static inline void +ovpn_set_peer_req_set_peer_keyconf_key_id(struct ovpn_set_peer_req *req, + __u32 key_id) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.key_id = 1; + req->peer.keyconf.key_id = key_id; +} +static inline void +ovpn_set_peer_req_set_peer_keyconf_cipher_alg(struct ovpn_set_peer_req *req, + enum ovpn_cipher_alg cipher_alg) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.cipher_alg = 1; + req->peer.keyconf.cipher_alg = cipher_alg; +} +static inline void +ovpn_set_peer_req_set_peer_keyconf_encrypt_dir_cipher_key(struct ovpn_set_peer_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.cipher_key); + req->peer.keyconf.encrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.encrypt_dir.cipher_key = malloc(req->peer.keyconf.encrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.encrypt_dir.cipher_key, cipher_key, req->peer.keyconf.encrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_set_peer_req_set_peer_keyconf_encrypt_dir_nonce_tail(struct ovpn_set_peer_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.nonce_tail); + req->peer.keyconf.encrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.encrypt_dir.nonce_tail = malloc(req->peer.keyconf.encrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.encrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.encrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_set_peer_req_set_peer_keyconf_decrypt_dir_cipher_key(struct ovpn_set_peer_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.cipher_key); + req->peer.keyconf.decrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.decrypt_dir.cipher_key = malloc(req->peer.keyconf.decrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.decrypt_dir.cipher_key, cipher_key, req->peer.keyconf.decrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_set_peer_req_set_peer_keyconf_decrypt_dir_nonce_tail(struct ovpn_set_peer_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.nonce_tail); + req->peer.keyconf.decrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.decrypt_dir.nonce_tail = malloc(req->peer.keyconf.decrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.decrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.decrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_set_peer_req_set_peer_vpn_rx_bytes(struct ovpn_set_peer_req *req, + __u64 vpn_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_bytes = 1; + req->peer.vpn_rx_bytes = vpn_rx_bytes; +} +static inline void +ovpn_set_peer_req_set_peer_vpn_tx_bytes(struct ovpn_set_peer_req *req, + __u64 vpn_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_bytes = 1; + req->peer.vpn_tx_bytes = vpn_tx_bytes; +} +static inline void +ovpn_set_peer_req_set_peer_vpn_rx_packets(struct ovpn_set_peer_req *req, + __u32 vpn_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_packets = 1; + req->peer.vpn_rx_packets = vpn_rx_packets; +} +static inline void +ovpn_set_peer_req_set_peer_vpn_tx_packets(struct ovpn_set_peer_req *req, + __u32 vpn_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_packets = 1; + req->peer.vpn_tx_packets = vpn_tx_packets; +} +static inline void +ovpn_set_peer_req_set_peer_link_rx_bytes(struct ovpn_set_peer_req *req, + __u64 link_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_rx_bytes = 1; + req->peer.link_rx_bytes = link_rx_bytes; +} +static inline void +ovpn_set_peer_req_set_peer_link_tx_bytes(struct ovpn_set_peer_req *req, + __u64 link_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_tx_bytes = 1; + req->peer.link_tx_bytes = link_tx_bytes; +} +static inline void +ovpn_set_peer_req_set_peer_link_rx_packets(struct ovpn_set_peer_req *req, + __u32 link_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_rx_packets = 1; + req->peer.link_rx_packets = link_rx_packets; +} +static inline void +ovpn_set_peer_req_set_peer_link_tx_packets(struct ovpn_set_peer_req *req, + __u32 link_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_tx_packets = 1; + req->peer.link_tx_packets = link_tx_packets; +} + +/* + * Add or modify a remote peer + */ +int ovpn_set_peer(struct ynl_sock *ys, struct ovpn_set_peer_req *req); + +/* ============== OVPN_CMD_GET_PEER ============== */ +/* OVPN_CMD_GET_PEER - do */ +struct ovpn_get_peer_req { + struct { + __u32 ifindex:1; + __u32 peer:1; + } _present; + + __u32 ifindex; + struct ovpn_peer peer; +}; + +static inline struct ovpn_get_peer_req *ovpn_get_peer_req_alloc(void) +{ + return calloc(1, sizeof(struct ovpn_get_peer_req)); +} +void ovpn_get_peer_req_free(struct ovpn_get_peer_req *req); + +static inline void +ovpn_get_peer_req_set_ifindex(struct ovpn_get_peer_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +ovpn_get_peer_req_set_peer_id(struct ovpn_get_peer_req *req, __u32 id) +{ + req->_present.peer = 1; + req->peer._present.id = 1; + req->peer.id = id; +} +static inline void +ovpn_get_peer_req_set_peer_sockaddr_remote(struct ovpn_get_peer_req *req, + const void *sockaddr_remote, + size_t len) +{ + req->_present.peer = 1; + free(req->peer.sockaddr_remote); + req->peer._present.sockaddr_remote_len = len; + req->peer.sockaddr_remote = malloc(req->peer._present.sockaddr_remote_len); + memcpy(req->peer.sockaddr_remote, sockaddr_remote, req->peer._present.sockaddr_remote_len); +} +static inline void +ovpn_get_peer_req_set_peer_socket(struct ovpn_get_peer_req *req, __u32 socket) +{ + req->_present.peer = 1; + req->peer._present.socket = 1; + req->peer.socket = socket; +} +static inline void +ovpn_get_peer_req_set_peer_vpn_ipv4(struct ovpn_get_peer_req *req, + __u32 vpn_ipv4) +{ + req->_present.peer = 1; + req->peer._present.vpn_ipv4 = 1; + req->peer.vpn_ipv4 = vpn_ipv4; +} +static inline void +ovpn_get_peer_req_set_peer_vpn_ipv6(struct ovpn_get_peer_req *req, + const void *vpn_ipv6, size_t len) +{ + req->_present.peer = 1; + free(req->peer.vpn_ipv6); + req->peer._present.vpn_ipv6_len = len; + req->peer.vpn_ipv6 = malloc(req->peer._present.vpn_ipv6_len); + memcpy(req->peer.vpn_ipv6, vpn_ipv6, req->peer._present.vpn_ipv6_len); +} +static inline void +ovpn_get_peer_req_set_peer_local_ip(struct ovpn_get_peer_req *req, + const void *local_ip, size_t len) +{ + req->_present.peer = 1; + free(req->peer.local_ip); + req->peer._present.local_ip_len = len; + req->peer.local_ip = malloc(req->peer._present.local_ip_len); + memcpy(req->peer.local_ip, local_ip, req->peer._present.local_ip_len); +} +static inline void +ovpn_get_peer_req_set_peer_local_port(struct ovpn_get_peer_req *req, + __u32 local_port) +{ + req->_present.peer = 1; + req->peer._present.local_port = 1; + req->peer.local_port = local_port; +} +static inline void +ovpn_get_peer_req_set_peer_keepalive_interval(struct ovpn_get_peer_req *req, + __u32 keepalive_interval) +{ + req->_present.peer = 1; + req->peer._present.keepalive_interval = 1; + req->peer.keepalive_interval = keepalive_interval; +} +static inline void +ovpn_get_peer_req_set_peer_keepalive_timeout(struct ovpn_get_peer_req *req, + __u32 keepalive_timeout) +{ + req->_present.peer = 1; + req->peer._present.keepalive_timeout = 1; + req->peer.keepalive_timeout = keepalive_timeout; +} +static inline void +ovpn_get_peer_req_set_peer_del_reason(struct ovpn_get_peer_req *req, + enum ovpn_del_peer_reason del_reason) +{ + req->_present.peer = 1; + req->peer._present.del_reason = 1; + req->peer.del_reason = del_reason; +} +static inline void +ovpn_get_peer_req_set_peer_keyconf_slot(struct ovpn_get_peer_req *req, + enum ovpn_key_slot slot) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.slot = 1; + req->peer.keyconf.slot = slot; +} +static inline void +ovpn_get_peer_req_set_peer_keyconf_key_id(struct ovpn_get_peer_req *req, + __u32 key_id) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.key_id = 1; + req->peer.keyconf.key_id = key_id; +} +static inline void +ovpn_get_peer_req_set_peer_keyconf_cipher_alg(struct ovpn_get_peer_req *req, + enum ovpn_cipher_alg cipher_alg) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.cipher_alg = 1; + req->peer.keyconf.cipher_alg = cipher_alg; +} +static inline void +ovpn_get_peer_req_set_peer_keyconf_encrypt_dir_cipher_key(struct ovpn_get_peer_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.cipher_key); + req->peer.keyconf.encrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.encrypt_dir.cipher_key = malloc(req->peer.keyconf.encrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.encrypt_dir.cipher_key, cipher_key, req->peer.keyconf.encrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_get_peer_req_set_peer_keyconf_encrypt_dir_nonce_tail(struct ovpn_get_peer_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.nonce_tail); + req->peer.keyconf.encrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.encrypt_dir.nonce_tail = malloc(req->peer.keyconf.encrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.encrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.encrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_get_peer_req_set_peer_keyconf_decrypt_dir_cipher_key(struct ovpn_get_peer_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.cipher_key); + req->peer.keyconf.decrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.decrypt_dir.cipher_key = malloc(req->peer.keyconf.decrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.decrypt_dir.cipher_key, cipher_key, req->peer.keyconf.decrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_get_peer_req_set_peer_keyconf_decrypt_dir_nonce_tail(struct ovpn_get_peer_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.nonce_tail); + req->peer.keyconf.decrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.decrypt_dir.nonce_tail = malloc(req->peer.keyconf.decrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.decrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.decrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_get_peer_req_set_peer_vpn_rx_bytes(struct ovpn_get_peer_req *req, + __u64 vpn_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_bytes = 1; + req->peer.vpn_rx_bytes = vpn_rx_bytes; +} +static inline void +ovpn_get_peer_req_set_peer_vpn_tx_bytes(struct ovpn_get_peer_req *req, + __u64 vpn_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_bytes = 1; + req->peer.vpn_tx_bytes = vpn_tx_bytes; +} +static inline void +ovpn_get_peer_req_set_peer_vpn_rx_packets(struct ovpn_get_peer_req *req, + __u32 vpn_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_packets = 1; + req->peer.vpn_rx_packets = vpn_rx_packets; +} +static inline void +ovpn_get_peer_req_set_peer_vpn_tx_packets(struct ovpn_get_peer_req *req, + __u32 vpn_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_packets = 1; + req->peer.vpn_tx_packets = vpn_tx_packets; +} +static inline void +ovpn_get_peer_req_set_peer_link_rx_bytes(struct ovpn_get_peer_req *req, + __u64 link_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_rx_bytes = 1; + req->peer.link_rx_bytes = link_rx_bytes; +} +static inline void +ovpn_get_peer_req_set_peer_link_tx_bytes(struct ovpn_get_peer_req *req, + __u64 link_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_tx_bytes = 1; + req->peer.link_tx_bytes = link_tx_bytes; +} +static inline void +ovpn_get_peer_req_set_peer_link_rx_packets(struct ovpn_get_peer_req *req, + __u32 link_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_rx_packets = 1; + req->peer.link_rx_packets = link_rx_packets; +} +static inline void +ovpn_get_peer_req_set_peer_link_tx_packets(struct ovpn_get_peer_req *req, + __u32 link_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_tx_packets = 1; + req->peer.link_tx_packets = link_tx_packets; +} + +struct ovpn_get_peer_rsp { + struct { + __u32 peer:1; + } _present; + + struct ovpn_peer peer; +}; + +void ovpn_get_peer_rsp_free(struct ovpn_get_peer_rsp *rsp); + +/* + * Retrieve data about existing remote peers (or a specific one) + */ +struct ovpn_get_peer_rsp * +ovpn_get_peer(struct ynl_sock *ys, struct ovpn_get_peer_req *req); + +/* OVPN_CMD_GET_PEER - dump */ +struct ovpn_get_peer_req_dump { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; +}; + +static inline struct ovpn_get_peer_req_dump *ovpn_get_peer_req_dump_alloc(void) +{ + return calloc(1, sizeof(struct ovpn_get_peer_req_dump)); +} +void ovpn_get_peer_req_dump_free(struct ovpn_get_peer_req_dump *req); + +static inline void +ovpn_get_peer_req_dump_set_ifindex(struct ovpn_get_peer_req_dump *req, + __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} + +struct ovpn_get_peer_list { + struct ovpn_get_peer_list *next; + struct ovpn_get_peer_rsp obj __attribute__((aligned(8))); +}; + +void ovpn_get_peer_list_free(struct ovpn_get_peer_list *rsp); + +struct ovpn_get_peer_list * +ovpn_get_peer_dump(struct ynl_sock *ys, struct ovpn_get_peer_req_dump *req); + +/* ============== OVPN_CMD_DEL_PEER ============== */ +/* OVPN_CMD_DEL_PEER - do */ +struct ovpn_del_peer_req { + struct { + __u32 ifindex:1; + __u32 peer:1; + } _present; + + __u32 ifindex; + struct ovpn_peer peer; +}; + +static inline struct ovpn_del_peer_req *ovpn_del_peer_req_alloc(void) +{ + return calloc(1, sizeof(struct ovpn_del_peer_req)); +} +void ovpn_del_peer_req_free(struct ovpn_del_peer_req *req); + +static inline void +ovpn_del_peer_req_set_ifindex(struct ovpn_del_peer_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +ovpn_del_peer_req_set_peer_id(struct ovpn_del_peer_req *req, __u32 id) +{ + req->_present.peer = 1; + req->peer._present.id = 1; + req->peer.id = id; +} +static inline void +ovpn_del_peer_req_set_peer_sockaddr_remote(struct ovpn_del_peer_req *req, + const void *sockaddr_remote, + size_t len) +{ + req->_present.peer = 1; + free(req->peer.sockaddr_remote); + req->peer._present.sockaddr_remote_len = len; + req->peer.sockaddr_remote = malloc(req->peer._present.sockaddr_remote_len); + memcpy(req->peer.sockaddr_remote, sockaddr_remote, req->peer._present.sockaddr_remote_len); +} +static inline void +ovpn_del_peer_req_set_peer_socket(struct ovpn_del_peer_req *req, __u32 socket) +{ + req->_present.peer = 1; + req->peer._present.socket = 1; + req->peer.socket = socket; +} +static inline void +ovpn_del_peer_req_set_peer_vpn_ipv4(struct ovpn_del_peer_req *req, + __u32 vpn_ipv4) +{ + req->_present.peer = 1; + req->peer._present.vpn_ipv4 = 1; + req->peer.vpn_ipv4 = vpn_ipv4; +} +static inline void +ovpn_del_peer_req_set_peer_vpn_ipv6(struct ovpn_del_peer_req *req, + const void *vpn_ipv6, size_t len) +{ + req->_present.peer = 1; + free(req->peer.vpn_ipv6); + req->peer._present.vpn_ipv6_len = len; + req->peer.vpn_ipv6 = malloc(req->peer._present.vpn_ipv6_len); + memcpy(req->peer.vpn_ipv6, vpn_ipv6, req->peer._present.vpn_ipv6_len); +} +static inline void +ovpn_del_peer_req_set_peer_local_ip(struct ovpn_del_peer_req *req, + const void *local_ip, size_t len) +{ + req->_present.peer = 1; + free(req->peer.local_ip); + req->peer._present.local_ip_len = len; + req->peer.local_ip = malloc(req->peer._present.local_ip_len); + memcpy(req->peer.local_ip, local_ip, req->peer._present.local_ip_len); +} +static inline void +ovpn_del_peer_req_set_peer_local_port(struct ovpn_del_peer_req *req, + __u32 local_port) +{ + req->_present.peer = 1; + req->peer._present.local_port = 1; + req->peer.local_port = local_port; +} +static inline void +ovpn_del_peer_req_set_peer_keepalive_interval(struct ovpn_del_peer_req *req, + __u32 keepalive_interval) +{ + req->_present.peer = 1; + req->peer._present.keepalive_interval = 1; + req->peer.keepalive_interval = keepalive_interval; +} +static inline void +ovpn_del_peer_req_set_peer_keepalive_timeout(struct ovpn_del_peer_req *req, + __u32 keepalive_timeout) +{ + req->_present.peer = 1; + req->peer._present.keepalive_timeout = 1; + req->peer.keepalive_timeout = keepalive_timeout; +} +static inline void +ovpn_del_peer_req_set_peer_del_reason(struct ovpn_del_peer_req *req, + enum ovpn_del_peer_reason del_reason) +{ + req->_present.peer = 1; + req->peer._present.del_reason = 1; + req->peer.del_reason = del_reason; +} +static inline void +ovpn_del_peer_req_set_peer_keyconf_slot(struct ovpn_del_peer_req *req, + enum ovpn_key_slot slot) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.slot = 1; + req->peer.keyconf.slot = slot; +} +static inline void +ovpn_del_peer_req_set_peer_keyconf_key_id(struct ovpn_del_peer_req *req, + __u32 key_id) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.key_id = 1; + req->peer.keyconf.key_id = key_id; +} +static inline void +ovpn_del_peer_req_set_peer_keyconf_cipher_alg(struct ovpn_del_peer_req *req, + enum ovpn_cipher_alg cipher_alg) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.cipher_alg = 1; + req->peer.keyconf.cipher_alg = cipher_alg; +} +static inline void +ovpn_del_peer_req_set_peer_keyconf_encrypt_dir_cipher_key(struct ovpn_del_peer_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.cipher_key); + req->peer.keyconf.encrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.encrypt_dir.cipher_key = malloc(req->peer.keyconf.encrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.encrypt_dir.cipher_key, cipher_key, req->peer.keyconf.encrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_del_peer_req_set_peer_keyconf_encrypt_dir_nonce_tail(struct ovpn_del_peer_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.nonce_tail); + req->peer.keyconf.encrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.encrypt_dir.nonce_tail = malloc(req->peer.keyconf.encrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.encrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.encrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_del_peer_req_set_peer_keyconf_decrypt_dir_cipher_key(struct ovpn_del_peer_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.cipher_key); + req->peer.keyconf.decrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.decrypt_dir.cipher_key = malloc(req->peer.keyconf.decrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.decrypt_dir.cipher_key, cipher_key, req->peer.keyconf.decrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_del_peer_req_set_peer_keyconf_decrypt_dir_nonce_tail(struct ovpn_del_peer_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.nonce_tail); + req->peer.keyconf.decrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.decrypt_dir.nonce_tail = malloc(req->peer.keyconf.decrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.decrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.decrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_del_peer_req_set_peer_vpn_rx_bytes(struct ovpn_del_peer_req *req, + __u64 vpn_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_bytes = 1; + req->peer.vpn_rx_bytes = vpn_rx_bytes; +} +static inline void +ovpn_del_peer_req_set_peer_vpn_tx_bytes(struct ovpn_del_peer_req *req, + __u64 vpn_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_bytes = 1; + req->peer.vpn_tx_bytes = vpn_tx_bytes; +} +static inline void +ovpn_del_peer_req_set_peer_vpn_rx_packets(struct ovpn_del_peer_req *req, + __u32 vpn_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_packets = 1; + req->peer.vpn_rx_packets = vpn_rx_packets; +} +static inline void +ovpn_del_peer_req_set_peer_vpn_tx_packets(struct ovpn_del_peer_req *req, + __u32 vpn_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_packets = 1; + req->peer.vpn_tx_packets = vpn_tx_packets; +} +static inline void +ovpn_del_peer_req_set_peer_link_rx_bytes(struct ovpn_del_peer_req *req, + __u64 link_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_rx_bytes = 1; + req->peer.link_rx_bytes = link_rx_bytes; +} +static inline void +ovpn_del_peer_req_set_peer_link_tx_bytes(struct ovpn_del_peer_req *req, + __u64 link_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_tx_bytes = 1; + req->peer.link_tx_bytes = link_tx_bytes; +} +static inline void +ovpn_del_peer_req_set_peer_link_rx_packets(struct ovpn_del_peer_req *req, + __u32 link_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_rx_packets = 1; + req->peer.link_rx_packets = link_rx_packets; +} +static inline void +ovpn_del_peer_req_set_peer_link_tx_packets(struct ovpn_del_peer_req *req, + __u32 link_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_tx_packets = 1; + req->peer.link_tx_packets = link_tx_packets; +} + +/* + * Delete existing remote peer + */ +int ovpn_del_peer(struct ynl_sock *ys, struct ovpn_del_peer_req *req); + +/* ============== OVPN_CMD_SET_KEY ============== */ +/* OVPN_CMD_SET_KEY - do */ +struct ovpn_set_key_req { + struct { + __u32 ifindex:1; + __u32 peer:1; + } _present; + + __u32 ifindex; + struct ovpn_peer peer; +}; + +static inline struct ovpn_set_key_req *ovpn_set_key_req_alloc(void) +{ + return calloc(1, sizeof(struct ovpn_set_key_req)); +} +void ovpn_set_key_req_free(struct ovpn_set_key_req *req); + +static inline void +ovpn_set_key_req_set_ifindex(struct ovpn_set_key_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +ovpn_set_key_req_set_peer_id(struct ovpn_set_key_req *req, __u32 id) +{ + req->_present.peer = 1; + req->peer._present.id = 1; + req->peer.id = id; +} +static inline void +ovpn_set_key_req_set_peer_sockaddr_remote(struct ovpn_set_key_req *req, + const void *sockaddr_remote, + size_t len) +{ + req->_present.peer = 1; + free(req->peer.sockaddr_remote); + req->peer._present.sockaddr_remote_len = len; + req->peer.sockaddr_remote = malloc(req->peer._present.sockaddr_remote_len); + memcpy(req->peer.sockaddr_remote, sockaddr_remote, req->peer._present.sockaddr_remote_len); +} +static inline void +ovpn_set_key_req_set_peer_socket(struct ovpn_set_key_req *req, __u32 socket) +{ + req->_present.peer = 1; + req->peer._present.socket = 1; + req->peer.socket = socket; +} +static inline void +ovpn_set_key_req_set_peer_vpn_ipv4(struct ovpn_set_key_req *req, + __u32 vpn_ipv4) +{ + req->_present.peer = 1; + req->peer._present.vpn_ipv4 = 1; + req->peer.vpn_ipv4 = vpn_ipv4; +} +static inline void +ovpn_set_key_req_set_peer_vpn_ipv6(struct ovpn_set_key_req *req, + const void *vpn_ipv6, size_t len) +{ + req->_present.peer = 1; + free(req->peer.vpn_ipv6); + req->peer._present.vpn_ipv6_len = len; + req->peer.vpn_ipv6 = malloc(req->peer._present.vpn_ipv6_len); + memcpy(req->peer.vpn_ipv6, vpn_ipv6, req->peer._present.vpn_ipv6_len); +} +static inline void +ovpn_set_key_req_set_peer_local_ip(struct ovpn_set_key_req *req, + const void *local_ip, size_t len) +{ + req->_present.peer = 1; + free(req->peer.local_ip); + req->peer._present.local_ip_len = len; + req->peer.local_ip = malloc(req->peer._present.local_ip_len); + memcpy(req->peer.local_ip, local_ip, req->peer._present.local_ip_len); +} +static inline void +ovpn_set_key_req_set_peer_local_port(struct ovpn_set_key_req *req, + __u32 local_port) +{ + req->_present.peer = 1; + req->peer._present.local_port = 1; + req->peer.local_port = local_port; +} +static inline void +ovpn_set_key_req_set_peer_keepalive_interval(struct ovpn_set_key_req *req, + __u32 keepalive_interval) +{ + req->_present.peer = 1; + req->peer._present.keepalive_interval = 1; + req->peer.keepalive_interval = keepalive_interval; +} +static inline void +ovpn_set_key_req_set_peer_keepalive_timeout(struct ovpn_set_key_req *req, + __u32 keepalive_timeout) +{ + req->_present.peer = 1; + req->peer._present.keepalive_timeout = 1; + req->peer.keepalive_timeout = keepalive_timeout; +} +static inline void +ovpn_set_key_req_set_peer_del_reason(struct ovpn_set_key_req *req, + enum ovpn_del_peer_reason del_reason) +{ + req->_present.peer = 1; + req->peer._present.del_reason = 1; + req->peer.del_reason = del_reason; +} +static inline void +ovpn_set_key_req_set_peer_keyconf_slot(struct ovpn_set_key_req *req, + enum ovpn_key_slot slot) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.slot = 1; + req->peer.keyconf.slot = slot; +} +static inline void +ovpn_set_key_req_set_peer_keyconf_key_id(struct ovpn_set_key_req *req, + __u32 key_id) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.key_id = 1; + req->peer.keyconf.key_id = key_id; +} +static inline void +ovpn_set_key_req_set_peer_keyconf_cipher_alg(struct ovpn_set_key_req *req, + enum ovpn_cipher_alg cipher_alg) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.cipher_alg = 1; + req->peer.keyconf.cipher_alg = cipher_alg; +} +static inline void +ovpn_set_key_req_set_peer_keyconf_encrypt_dir_cipher_key(struct ovpn_set_key_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.cipher_key); + req->peer.keyconf.encrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.encrypt_dir.cipher_key = malloc(req->peer.keyconf.encrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.encrypt_dir.cipher_key, cipher_key, req->peer.keyconf.encrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_set_key_req_set_peer_keyconf_encrypt_dir_nonce_tail(struct ovpn_set_key_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.nonce_tail); + req->peer.keyconf.encrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.encrypt_dir.nonce_tail = malloc(req->peer.keyconf.encrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.encrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.encrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_set_key_req_set_peer_keyconf_decrypt_dir_cipher_key(struct ovpn_set_key_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.cipher_key); + req->peer.keyconf.decrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.decrypt_dir.cipher_key = malloc(req->peer.keyconf.decrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.decrypt_dir.cipher_key, cipher_key, req->peer.keyconf.decrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_set_key_req_set_peer_keyconf_decrypt_dir_nonce_tail(struct ovpn_set_key_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.nonce_tail); + req->peer.keyconf.decrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.decrypt_dir.nonce_tail = malloc(req->peer.keyconf.decrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.decrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.decrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_set_key_req_set_peer_vpn_rx_bytes(struct ovpn_set_key_req *req, + __u64 vpn_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_bytes = 1; + req->peer.vpn_rx_bytes = vpn_rx_bytes; +} +static inline void +ovpn_set_key_req_set_peer_vpn_tx_bytes(struct ovpn_set_key_req *req, + __u64 vpn_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_bytes = 1; + req->peer.vpn_tx_bytes = vpn_tx_bytes; +} +static inline void +ovpn_set_key_req_set_peer_vpn_rx_packets(struct ovpn_set_key_req *req, + __u32 vpn_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_packets = 1; + req->peer.vpn_rx_packets = vpn_rx_packets; +} +static inline void +ovpn_set_key_req_set_peer_vpn_tx_packets(struct ovpn_set_key_req *req, + __u32 vpn_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_packets = 1; + req->peer.vpn_tx_packets = vpn_tx_packets; +} +static inline void +ovpn_set_key_req_set_peer_link_rx_bytes(struct ovpn_set_key_req *req, + __u64 link_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_rx_bytes = 1; + req->peer.link_rx_bytes = link_rx_bytes; +} +static inline void +ovpn_set_key_req_set_peer_link_tx_bytes(struct ovpn_set_key_req *req, + __u64 link_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_tx_bytes = 1; + req->peer.link_tx_bytes = link_tx_bytes; +} +static inline void +ovpn_set_key_req_set_peer_link_rx_packets(struct ovpn_set_key_req *req, + __u32 link_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_rx_packets = 1; + req->peer.link_rx_packets = link_rx_packets; +} +static inline void +ovpn_set_key_req_set_peer_link_tx_packets(struct ovpn_set_key_req *req, + __u32 link_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_tx_packets = 1; + req->peer.link_tx_packets = link_tx_packets; +} + +/* + * Add or modify a cipher key for a specific peer + */ +int ovpn_set_key(struct ynl_sock *ys, struct ovpn_set_key_req *req); + +/* ============== OVPN_CMD_SWAP_KEYS ============== */ +/* OVPN_CMD_SWAP_KEYS - do */ +struct ovpn_swap_keys_req { + struct { + __u32 ifindex:1; + __u32 peer:1; + } _present; + + __u32 ifindex; + struct ovpn_peer peer; +}; + +static inline struct ovpn_swap_keys_req *ovpn_swap_keys_req_alloc(void) +{ + return calloc(1, sizeof(struct ovpn_swap_keys_req)); +} +void ovpn_swap_keys_req_free(struct ovpn_swap_keys_req *req); + +static inline void +ovpn_swap_keys_req_set_ifindex(struct ovpn_swap_keys_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +ovpn_swap_keys_req_set_peer_id(struct ovpn_swap_keys_req *req, __u32 id) +{ + req->_present.peer = 1; + req->peer._present.id = 1; + req->peer.id = id; +} +static inline void +ovpn_swap_keys_req_set_peer_sockaddr_remote(struct ovpn_swap_keys_req *req, + const void *sockaddr_remote, + size_t len) +{ + req->_present.peer = 1; + free(req->peer.sockaddr_remote); + req->peer._present.sockaddr_remote_len = len; + req->peer.sockaddr_remote = malloc(req->peer._present.sockaddr_remote_len); + memcpy(req->peer.sockaddr_remote, sockaddr_remote, req->peer._present.sockaddr_remote_len); +} +static inline void +ovpn_swap_keys_req_set_peer_socket(struct ovpn_swap_keys_req *req, + __u32 socket) +{ + req->_present.peer = 1; + req->peer._present.socket = 1; + req->peer.socket = socket; +} +static inline void +ovpn_swap_keys_req_set_peer_vpn_ipv4(struct ovpn_swap_keys_req *req, + __u32 vpn_ipv4) +{ + req->_present.peer = 1; + req->peer._present.vpn_ipv4 = 1; + req->peer.vpn_ipv4 = vpn_ipv4; +} +static inline void +ovpn_swap_keys_req_set_peer_vpn_ipv6(struct ovpn_swap_keys_req *req, + const void *vpn_ipv6, size_t len) +{ + req->_present.peer = 1; + free(req->peer.vpn_ipv6); + req->peer._present.vpn_ipv6_len = len; + req->peer.vpn_ipv6 = malloc(req->peer._present.vpn_ipv6_len); + memcpy(req->peer.vpn_ipv6, vpn_ipv6, req->peer._present.vpn_ipv6_len); +} +static inline void +ovpn_swap_keys_req_set_peer_local_ip(struct ovpn_swap_keys_req *req, + const void *local_ip, size_t len) +{ + req->_present.peer = 1; + free(req->peer.local_ip); + req->peer._present.local_ip_len = len; + req->peer.local_ip = malloc(req->peer._present.local_ip_len); + memcpy(req->peer.local_ip, local_ip, req->peer._present.local_ip_len); +} +static inline void +ovpn_swap_keys_req_set_peer_local_port(struct ovpn_swap_keys_req *req, + __u32 local_port) +{ + req->_present.peer = 1; + req->peer._present.local_port = 1; + req->peer.local_port = local_port; +} +static inline void +ovpn_swap_keys_req_set_peer_keepalive_interval(struct ovpn_swap_keys_req *req, + __u32 keepalive_interval) +{ + req->_present.peer = 1; + req->peer._present.keepalive_interval = 1; + req->peer.keepalive_interval = keepalive_interval; +} +static inline void +ovpn_swap_keys_req_set_peer_keepalive_timeout(struct ovpn_swap_keys_req *req, + __u32 keepalive_timeout) +{ + req->_present.peer = 1; + req->peer._present.keepalive_timeout = 1; + req->peer.keepalive_timeout = keepalive_timeout; +} +static inline void +ovpn_swap_keys_req_set_peer_del_reason(struct ovpn_swap_keys_req *req, + enum ovpn_del_peer_reason del_reason) +{ + req->_present.peer = 1; + req->peer._present.del_reason = 1; + req->peer.del_reason = del_reason; +} +static inline void +ovpn_swap_keys_req_set_peer_keyconf_slot(struct ovpn_swap_keys_req *req, + enum ovpn_key_slot slot) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.slot = 1; + req->peer.keyconf.slot = slot; +} +static inline void +ovpn_swap_keys_req_set_peer_keyconf_key_id(struct ovpn_swap_keys_req *req, + __u32 key_id) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.key_id = 1; + req->peer.keyconf.key_id = key_id; +} +static inline void +ovpn_swap_keys_req_set_peer_keyconf_cipher_alg(struct ovpn_swap_keys_req *req, + enum ovpn_cipher_alg cipher_alg) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.cipher_alg = 1; + req->peer.keyconf.cipher_alg = cipher_alg; +} +static inline void +ovpn_swap_keys_req_set_peer_keyconf_encrypt_dir_cipher_key(struct ovpn_swap_keys_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.cipher_key); + req->peer.keyconf.encrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.encrypt_dir.cipher_key = malloc(req->peer.keyconf.encrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.encrypt_dir.cipher_key, cipher_key, req->peer.keyconf.encrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_swap_keys_req_set_peer_keyconf_encrypt_dir_nonce_tail(struct ovpn_swap_keys_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.nonce_tail); + req->peer.keyconf.encrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.encrypt_dir.nonce_tail = malloc(req->peer.keyconf.encrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.encrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.encrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_swap_keys_req_set_peer_keyconf_decrypt_dir_cipher_key(struct ovpn_swap_keys_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.cipher_key); + req->peer.keyconf.decrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.decrypt_dir.cipher_key = malloc(req->peer.keyconf.decrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.decrypt_dir.cipher_key, cipher_key, req->peer.keyconf.decrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_swap_keys_req_set_peer_keyconf_decrypt_dir_nonce_tail(struct ovpn_swap_keys_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.nonce_tail); + req->peer.keyconf.decrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.decrypt_dir.nonce_tail = malloc(req->peer.keyconf.decrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.decrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.decrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_swap_keys_req_set_peer_vpn_rx_bytes(struct ovpn_swap_keys_req *req, + __u64 vpn_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_bytes = 1; + req->peer.vpn_rx_bytes = vpn_rx_bytes; +} +static inline void +ovpn_swap_keys_req_set_peer_vpn_tx_bytes(struct ovpn_swap_keys_req *req, + __u64 vpn_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_bytes = 1; + req->peer.vpn_tx_bytes = vpn_tx_bytes; +} +static inline void +ovpn_swap_keys_req_set_peer_vpn_rx_packets(struct ovpn_swap_keys_req *req, + __u32 vpn_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_packets = 1; + req->peer.vpn_rx_packets = vpn_rx_packets; +} +static inline void +ovpn_swap_keys_req_set_peer_vpn_tx_packets(struct ovpn_swap_keys_req *req, + __u32 vpn_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_packets = 1; + req->peer.vpn_tx_packets = vpn_tx_packets; +} +static inline void +ovpn_swap_keys_req_set_peer_link_rx_bytes(struct ovpn_swap_keys_req *req, + __u64 link_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_rx_bytes = 1; + req->peer.link_rx_bytes = link_rx_bytes; +} +static inline void +ovpn_swap_keys_req_set_peer_link_tx_bytes(struct ovpn_swap_keys_req *req, + __u64 link_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_tx_bytes = 1; + req->peer.link_tx_bytes = link_tx_bytes; +} +static inline void +ovpn_swap_keys_req_set_peer_link_rx_packets(struct ovpn_swap_keys_req *req, + __u32 link_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_rx_packets = 1; + req->peer.link_rx_packets = link_rx_packets; +} +static inline void +ovpn_swap_keys_req_set_peer_link_tx_packets(struct ovpn_swap_keys_req *req, + __u32 link_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_tx_packets = 1; + req->peer.link_tx_packets = link_tx_packets; +} + +/* + * Swap primary and secondary session keys for a specific peer + */ +int ovpn_swap_keys(struct ynl_sock *ys, struct ovpn_swap_keys_req *req); + +/* ============== OVPN_CMD_DEL_KEY ============== */ +/* OVPN_CMD_DEL_KEY - do */ +struct ovpn_del_key_req { + struct { + __u32 ifindex:1; + __u32 peer:1; + } _present; + + __u32 ifindex; + struct ovpn_peer peer; +}; + +static inline struct ovpn_del_key_req *ovpn_del_key_req_alloc(void) +{ + return calloc(1, sizeof(struct ovpn_del_key_req)); +} +void ovpn_del_key_req_free(struct ovpn_del_key_req *req); + +static inline void +ovpn_del_key_req_set_ifindex(struct ovpn_del_key_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +ovpn_del_key_req_set_peer_id(struct ovpn_del_key_req *req, __u32 id) +{ + req->_present.peer = 1; + req->peer._present.id = 1; + req->peer.id = id; +} +static inline void +ovpn_del_key_req_set_peer_sockaddr_remote(struct ovpn_del_key_req *req, + const void *sockaddr_remote, + size_t len) +{ + req->_present.peer = 1; + free(req->peer.sockaddr_remote); + req->peer._present.sockaddr_remote_len = len; + req->peer.sockaddr_remote = malloc(req->peer._present.sockaddr_remote_len); + memcpy(req->peer.sockaddr_remote, sockaddr_remote, req->peer._present.sockaddr_remote_len); +} +static inline void +ovpn_del_key_req_set_peer_socket(struct ovpn_del_key_req *req, __u32 socket) +{ + req->_present.peer = 1; + req->peer._present.socket = 1; + req->peer.socket = socket; +} +static inline void +ovpn_del_key_req_set_peer_vpn_ipv4(struct ovpn_del_key_req *req, + __u32 vpn_ipv4) +{ + req->_present.peer = 1; + req->peer._present.vpn_ipv4 = 1; + req->peer.vpn_ipv4 = vpn_ipv4; +} +static inline void +ovpn_del_key_req_set_peer_vpn_ipv6(struct ovpn_del_key_req *req, + const void *vpn_ipv6, size_t len) +{ + req->_present.peer = 1; + free(req->peer.vpn_ipv6); + req->peer._present.vpn_ipv6_len = len; + req->peer.vpn_ipv6 = malloc(req->peer._present.vpn_ipv6_len); + memcpy(req->peer.vpn_ipv6, vpn_ipv6, req->peer._present.vpn_ipv6_len); +} +static inline void +ovpn_del_key_req_set_peer_local_ip(struct ovpn_del_key_req *req, + const void *local_ip, size_t len) +{ + req->_present.peer = 1; + free(req->peer.local_ip); + req->peer._present.local_ip_len = len; + req->peer.local_ip = malloc(req->peer._present.local_ip_len); + memcpy(req->peer.local_ip, local_ip, req->peer._present.local_ip_len); +} +static inline void +ovpn_del_key_req_set_peer_local_port(struct ovpn_del_key_req *req, + __u32 local_port) +{ + req->_present.peer = 1; + req->peer._present.local_port = 1; + req->peer.local_port = local_port; +} +static inline void +ovpn_del_key_req_set_peer_keepalive_interval(struct ovpn_del_key_req *req, + __u32 keepalive_interval) +{ + req->_present.peer = 1; + req->peer._present.keepalive_interval = 1; + req->peer.keepalive_interval = keepalive_interval; +} +static inline void +ovpn_del_key_req_set_peer_keepalive_timeout(struct ovpn_del_key_req *req, + __u32 keepalive_timeout) +{ + req->_present.peer = 1; + req->peer._present.keepalive_timeout = 1; + req->peer.keepalive_timeout = keepalive_timeout; +} +static inline void +ovpn_del_key_req_set_peer_del_reason(struct ovpn_del_key_req *req, + enum ovpn_del_peer_reason del_reason) +{ + req->_present.peer = 1; + req->peer._present.del_reason = 1; + req->peer.del_reason = del_reason; +} +static inline void +ovpn_del_key_req_set_peer_keyconf_slot(struct ovpn_del_key_req *req, + enum ovpn_key_slot slot) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.slot = 1; + req->peer.keyconf.slot = slot; +} +static inline void +ovpn_del_key_req_set_peer_keyconf_key_id(struct ovpn_del_key_req *req, + __u32 key_id) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.key_id = 1; + req->peer.keyconf.key_id = key_id; +} +static inline void +ovpn_del_key_req_set_peer_keyconf_cipher_alg(struct ovpn_del_key_req *req, + enum ovpn_cipher_alg cipher_alg) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.cipher_alg = 1; + req->peer.keyconf.cipher_alg = cipher_alg; +} +static inline void +ovpn_del_key_req_set_peer_keyconf_encrypt_dir_cipher_key(struct ovpn_del_key_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.cipher_key); + req->peer.keyconf.encrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.encrypt_dir.cipher_key = malloc(req->peer.keyconf.encrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.encrypt_dir.cipher_key, cipher_key, req->peer.keyconf.encrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_del_key_req_set_peer_keyconf_encrypt_dir_nonce_tail(struct ovpn_del_key_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.encrypt_dir = 1; + free(req->peer.keyconf.encrypt_dir.nonce_tail); + req->peer.keyconf.encrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.encrypt_dir.nonce_tail = malloc(req->peer.keyconf.encrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.encrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.encrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_del_key_req_set_peer_keyconf_decrypt_dir_cipher_key(struct ovpn_del_key_req *req, + const void *cipher_key, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.cipher_key); + req->peer.keyconf.decrypt_dir._present.cipher_key_len = len; + req->peer.keyconf.decrypt_dir.cipher_key = malloc(req->peer.keyconf.decrypt_dir._present.cipher_key_len); + memcpy(req->peer.keyconf.decrypt_dir.cipher_key, cipher_key, req->peer.keyconf.decrypt_dir._present.cipher_key_len); +} +static inline void +ovpn_del_key_req_set_peer_keyconf_decrypt_dir_nonce_tail(struct ovpn_del_key_req *req, + const void *nonce_tail, + size_t len) +{ + req->_present.peer = 1; + req->peer._present.keyconf = 1; + req->peer.keyconf._present.decrypt_dir = 1; + free(req->peer.keyconf.decrypt_dir.nonce_tail); + req->peer.keyconf.decrypt_dir._present.nonce_tail_len = len; + req->peer.keyconf.decrypt_dir.nonce_tail = malloc(req->peer.keyconf.decrypt_dir._present.nonce_tail_len); + memcpy(req->peer.keyconf.decrypt_dir.nonce_tail, nonce_tail, req->peer.keyconf.decrypt_dir._present.nonce_tail_len); +} +static inline void +ovpn_del_key_req_set_peer_vpn_rx_bytes(struct ovpn_del_key_req *req, + __u64 vpn_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_bytes = 1; + req->peer.vpn_rx_bytes = vpn_rx_bytes; +} +static inline void +ovpn_del_key_req_set_peer_vpn_tx_bytes(struct ovpn_del_key_req *req, + __u64 vpn_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_bytes = 1; + req->peer.vpn_tx_bytes = vpn_tx_bytes; +} +static inline void +ovpn_del_key_req_set_peer_vpn_rx_packets(struct ovpn_del_key_req *req, + __u32 vpn_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_rx_packets = 1; + req->peer.vpn_rx_packets = vpn_rx_packets; +} +static inline void +ovpn_del_key_req_set_peer_vpn_tx_packets(struct ovpn_del_key_req *req, + __u32 vpn_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.vpn_tx_packets = 1; + req->peer.vpn_tx_packets = vpn_tx_packets; +} +static inline void +ovpn_del_key_req_set_peer_link_rx_bytes(struct ovpn_del_key_req *req, + __u64 link_rx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_rx_bytes = 1; + req->peer.link_rx_bytes = link_rx_bytes; +} +static inline void +ovpn_del_key_req_set_peer_link_tx_bytes(struct ovpn_del_key_req *req, + __u64 link_tx_bytes) +{ + req->_present.peer = 1; + req->peer._present.link_tx_bytes = 1; + req->peer.link_tx_bytes = link_tx_bytes; +} +static inline void +ovpn_del_key_req_set_peer_link_rx_packets(struct ovpn_del_key_req *req, + __u32 link_rx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_rx_packets = 1; + req->peer.link_rx_packets = link_rx_packets; +} +static inline void +ovpn_del_key_req_set_peer_link_tx_packets(struct ovpn_del_key_req *req, + __u32 link_tx_packets) +{ + req->_present.peer = 1; + req->peer._present.link_tx_packets = 1; + req->peer.link_tx_packets = link_tx_packets; +} + +/* + * Delete cipher key for a specific peer + */ +int ovpn_del_key(struct ynl_sock *ys, struct ovpn_del_key_req *req); + +#endif /* _LINUX_OVPN_GEN_H */