20#include <netlink-private/netlink.h>
21#include <netlink/netlink.h>
22#include <netlink/attr.h>
23#include <netlink/utils.h>
24#include <netlink/object.h>
25#include <netlink/route/rtnl.h>
26#include <netlink-private/route/link/api.h>
27#include <netlink/route/link/vrf.h>
29#include <linux/if_link.h>
30#include <linux-private/linux/rtnetlink.h>
32#define VRF_TABLE_ID_MAX RT_TABLE_MAX
35#define VRF_HAS_TABLE_ID (1<<0)
44static struct nla_policy vrf_policy[IFLA_VRF_MAX + 1] = {
48static int vrf_alloc(
struct rtnl_link *link)
53 memset(link->l_info, 0, sizeof (*vi));
57 if ((vi = calloc(1,
sizeof(*vi))) == NULL)
65static int vrf_parse(
struct rtnl_link *link,
struct nlattr *data,
66 struct nlattr *xstats)
68 struct nlattr *tb[IFLA_VRF_MAX+1];
72 NL_DBG(3,
"Parsing VRF link info");
77 if ((err = vrf_alloc(link)) < 0)
82 if (tb[IFLA_VRF_TABLE]) {
84 vi->vi_mask |= VRF_HAS_TABLE_ID;
93static void vrf_free(
struct rtnl_link *link)
101 struct vrf_info *vdst, *vsrc = src->l_info;
109 BUG_ON(!vdst || !vsrc);
111 memcpy(vdst, vsrc,
sizeof(
struct vrf_info));
116static int vrf_put_attrs(
struct nl_msg *msg,
struct rtnl_link *link)
118 struct vrf_info *vi = link->l_info;
124 if (vi->vi_mask & VRF_HAS_TABLE_ID) {
137 struct vrf_info *vi = link->l_info;
139 if (vi->vi_mask & VRF_HAS_TABLE_ID) {
140 nl_dump(p,
"table-id %u", vi->table_id);
144static struct rtnl_link_info_ops vrf_info_ops = {
146 .io_alloc = vrf_alloc,
147 .io_parse = vrf_parse,
152 .io_clone = vrf_clone,
153 .io_put_attrs = vrf_put_attrs,
158#define IS_VRF_LINK_ASSERT(link) \
159 if ((link)->l_info_ops != &vrf_info_ops) { \
160 APPBUG("Link is not a VRF link. set type \"vrf\" first."); \
161 return -NLE_OPNOTSUPP; \
198 return link->l_info_ops && !strcmp(link->l_info_ops->io_name,
"vrf");
210 struct vrf_info *vi = link->l_info;
212 IS_VRF_LINK_ASSERT(link);
216 if (vi->vi_mask & VRF_HAS_TABLE_ID)
233 struct vrf_info *vi = link->l_info;
235 IS_VRF_LINK_ASSERT(link);
237 _NL_STATIC_ASSERT(VRF_TABLE_ID_MAX == UINT32_MAX);
240 vi->vi_mask |= VRF_HAS_TABLE_ID;
247static void __init vrf_init(
void)
252static void __exit vrf_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.
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_is_vrf(struct rtnl_link *link)
Check if link is a VRF link.
int rtnl_link_vrf_set_tableid(struct rtnl_link *link, uint32_t id)
Set VRF table id.
int rtnl_link_vrf_get_tableid(struct rtnl_link *link, uint32_t *id)
Get VRF table id.
struct rtnl_link * rtnl_link_vrf_alloc(void)
Allocate link object of type VRF.
Attribute validation policy.
uint16_t type
Type of attribute or NLA_UNSPEC.