20#include "nl-default.h"
22#include <linux/if_link.h>
23#include <linux/rtnetlink.h>
25#include <netlink/netlink.h>
26#include <netlink/attr.h>
27#include <netlink/utils.h>
28#include <netlink/object.h>
29#include <netlink/route/rtnl.h>
30#include <netlink/route/link/vrf.h>
35#define VRF_TABLE_ID_MAX RT_TABLE_MAX
38#define VRF_HAS_TABLE_ID (1<<0)
51static int vrf_alloc(
struct rtnl_link *link)
56 memset(link->l_info, 0, sizeof (*vi));
60 if ((vi = calloc(1,
sizeof(*vi))) == NULL)
68static int vrf_parse(
struct rtnl_link *link,
struct nlattr *data,
69 struct nlattr *xstats)
71 struct nlattr *tb[IFLA_VRF_MAX+1];
75 NL_DBG(3,
"Parsing VRF link info");
80 if ((err = vrf_alloc(link)) < 0)
85 if (tb[IFLA_VRF_TABLE]) {
87 vi->vi_mask |= VRF_HAS_TABLE_ID;
96static void vrf_free(
struct rtnl_link *link)
104 struct vrf_info *vdst, *vsrc = src->l_info;
112 BUG_ON(!vdst || !vsrc);
114 memcpy(vdst, vsrc,
sizeof(
struct vrf_info));
119static int vrf_put_attrs(
struct nl_msg *msg,
struct rtnl_link *link)
121 struct vrf_info *vi = link->l_info;
127 if (vi->vi_mask & VRF_HAS_TABLE_ID) {
140 struct vrf_info *vi = link->l_info;
142 if (vi->vi_mask & VRF_HAS_TABLE_ID) {
143 nl_dump(p,
"table-id %u", vi->table_id);
149 .io_alloc = vrf_alloc,
150 .io_parse = vrf_parse,
155 .io_clone = vrf_clone,
156 .io_put_attrs = vrf_put_attrs,
161#define IS_VRF_LINK_ASSERT(link) \
162 if ((link)->l_info_ops != &vrf_info_ops) { \
163 APPBUG("Link is not a VRF link. set type \"vrf\" first."); \
164 return -NLE_OPNOTSUPP; \
201 return link->l_info_ops && !strcmp(link->l_info_ops->
io_name,
"vrf");
213 struct vrf_info *vi = link->l_info;
215 IS_VRF_LINK_ASSERT(link);
219 if (vi->vi_mask & VRF_HAS_TABLE_ID)
236 struct vrf_info *vi = link->l_info;
238 IS_VRF_LINK_ASSERT(link);
240 _NL_STATIC_ASSERT(VRF_TABLE_ID_MAX == UINT32_MAX);
243 vi->vi_mask |= VRF_HAS_TABLE_ID;
250static void _nl_init vrf_init(
void)
255static void _nl_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)
Release 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.
Available operations to modules implementing a link info type.
char * io_name
Name of link info type, must match name on kernel side.