21#include <netlink-private/netlink.h>
22#include <netlink/netlink.h>
23#include <netlink/attr.h>
24#include <netlink/utils.h>
25#include <netlink/object.h>
26#include <netlink/route/rtnl.h>
27#include <netlink/route/link/xfrmi.h>
28#include <netlink-private/route/link/api.h>
30#define XFRMI_ATTR_LINK (1 << 0)
31#define XFRMI_ATTR_IF_ID (1 << 1)
33#define XFRMI_LINK_TYPE_NAME "xfrm"
41static struct nla_policy xfrmi_policy[IFLA_XFRM_MAX + 1] = {
43 [IFLA_XFRM_IF_ID] = { .type =
NLA_U32 },
46static int xfrmi_alloc(
struct rtnl_link *link)
51 memset(link->l_info, 0,
sizeof(*xfrmi));
53 xfrmi = calloc(1,
sizeof(*xfrmi));
63static int xfrmi_parse(
struct rtnl_link *link,
struct nlattr *data,
64 struct nlattr *xstats)
66 struct nlattr *tb[IFLA_XFRM_MAX + 1];
70 NL_DBG(3,
"Parsing XFRMI link info\n");
76 err = xfrmi_alloc(link);
82 if (tb[IFLA_XFRM_LINK]) {
84 xfrmi->xfrmi_mask |= XFRMI_ATTR_LINK;
87 if (tb[IFLA_XFRM_IF_ID]) {
89 xfrmi->xfrmi_mask |= XFRMI_ATTR_IF_ID;
95static int xfrmi_put_attrs(
struct nl_msg *msg,
struct rtnl_link *link)
104 if (xfrmi->xfrmi_mask & XFRMI_ATTR_LINK)
107 if (xfrmi->xfrmi_mask & XFRMI_ATTR_IF_ID)
116static void xfrmi_free(
struct rtnl_link *link)
126 nl_dump(p,
"xfrmi : %s", link->l_name);
133 if (xfrmi->xfrmi_mask & XFRMI_ATTR_LINK) {
140 parent = link_lookup(link->ce_cache, xfrmi->link);
145 nl_dump_line(p,
"%s\n", name);
147 nl_dump_line(p,
"%u\n", xfrmi->link);
150 if (xfrmi->xfrmi_mask & XFRMI_ATTR_IF_ID) {
152 nl_dump_line(p,
"%x\n", xfrmi->if_id);
158 struct xfrmi_info *xfrmi_dst, *xfrmi_src = src->l_info;
167 xfrmi_dst = dst->l_info;
169 if (!xfrmi_dst || !xfrmi_src)
172 memcpy(xfrmi_dst, xfrmi_src,
sizeof(
struct xfrmi_info));
177static struct rtnl_link_info_ops xfrmi_info_ops = {
178 .io_name = XFRMI_LINK_TYPE_NAME,
179 .io_alloc = xfrmi_alloc,
180 .io_parse = xfrmi_parse,
185 .io_clone = xfrmi_clone,
186 .io_put_attrs = xfrmi_put_attrs,
187 .io_free = xfrmi_free,
190#define IS_XFRMI_LINK_ASSERT(link) do { \
191 if ((link)->l_info_ops != &xfrmi_info_ops) { \
192 APPBUG("Link is not a xfrmi link. set type \"xfrmi\" first."); \
193 return -NLE_OPNOTSUPP; \
197struct rtnl_link *rtnl_link_xfrmi_alloc(
void)
223 return link->l_info_ops && !strcmp(link->l_info_ops->io_name,
224 XFRMI_LINK_TYPE_NAME);
238 IS_XFRMI_LINK_ASSERT(link);
241 xfrmi->xfrmi_mask |= XFRMI_ATTR_LINK;
257 IS_XFRMI_LINK_ASSERT(link);
259 if (!(xfrmi->xfrmi_mask & XFRMI_ATTR_LINK))
262 *out_link = xfrmi->link;
277 IS_XFRMI_LINK_ASSERT(link);
279 xfrmi->if_id = if_id;
280 xfrmi->xfrmi_mask |= XFRMI_ATTR_IF_ID;
296 IS_XFRMI_LINK_ASSERT(link);
298 if (!(xfrmi->xfrmi_mask & XFRMI_ATTR_IF_ID))
301 *out_if_id = xfrmi->if_id;
305static void __init xfrmi_init(
void)
310static void __exit xfrmi_exit(
void)
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
struct nlattr * nla_nest_start(struct nl_msg *msg, int attrtype)
Start a new level of nested attributes.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy)
Create attribute index based on nested attribute.
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes.
int rtnl_link_register_info(struct rtnl_link_info_ops *ops)
Register operations for a link info type.
int rtnl_link_unregister_info(struct rtnl_link_info_ops *ops)
Unregister operations for a link info type.
struct rtnl_link * rtnl_link_alloc(void)
Allocate link object.
char * rtnl_link_get_name(struct rtnl_link *link)
Return name of link object.
void rtnl_link_put(struct rtnl_link *link)
Return a link object reference.
int rtnl_link_set_type(struct rtnl_link *link, const char *type)
Set type of link object.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
int rtnl_link_xfrmi_set_link(struct rtnl_link *link, uint32_t index)
Set XFRMI link interface index.
int rtnl_link_is_xfrmi(struct rtnl_link *link)
Check if link is a XFRMI link.
int rtnl_link_xfrmi_set_if_id(struct rtnl_link *link, uint32_t if_id)
Set XFRMI if_id.
int rtnl_link_xfrmi_get_if_id(struct rtnl_link *link, uint32_t *out_if_id)
Get XFRMI if_id.
int rtnl_link_xfrmi_get_link(struct rtnl_link *link, uint32_t *out_link)
Get XFRMI link interface index.
Attribute validation policy.
uint16_t type
Type of attribute or NLA_UNSPEC.