19#include <netlink-private/netlink.h>
20#include <netlink/netlink.h>
21#include <netlink/attr.h>
22#include <netlink/utils.h>
23#include <netlink/object.h>
24#include <netlink/route/rtnl.h>
25#include <netlink-private/route/link/api.h>
26#include <netlink/route/link/ipvlan.h>
28#include <linux/if_link.h>
31#define IPVLAN_HAS_MODE (1<<0)
41static struct nla_policy ipvlan_policy[IFLA_IPVLAN_MAX+1] = {
45static int ipvlan_alloc(
struct rtnl_link *link)
47 struct ipvlan_info *ipi;
50 memset(link->l_info, 0,
sizeof(*ipi));
52 if ((ipi = calloc(1,
sizeof(*ipi))) == NULL)
61static int ipvlan_parse(
struct rtnl_link *link,
struct nlattr *data,
62 struct nlattr *xstats)
64 struct nlattr *tb[IFLA_IPVLAN_MAX+1];
65 struct ipvlan_info *ipi;
68 NL_DBG(3,
"Parsing IPVLAN link info\n");
73 if ((err = ipvlan_alloc(link)) < 0)
78 if (tb[IFLA_IPVLAN_MODE]) {
80 ipi->ipi_mask |= IPVLAN_HAS_MODE;
88static void ipvlan_free(
struct rtnl_link *link)
97 struct ipvlan_info *ipi = link->l_info;
99 if (ipi->ipi_mask & IPVLAN_HAS_MODE) {
100 rtnl_link_ipvlan_mode2str(ipi->ipi_mode, buf,
sizeof(buf));
101 nl_dump(p,
"ipvlan-mode %s", buf);
107 struct ipvlan_info *vdst, *vsrc = src->l_info;
118 memcpy(vdst, vsrc,
sizeof(
struct ipvlan_info));
123static int ipvlan_put_attrs(
struct nl_msg *msg,
struct rtnl_link *link)
125 struct ipvlan_info *ipi = link->l_info;
131 if (ipi->ipi_mask & IPVLAN_HAS_MODE)
141static struct rtnl_link_info_ops ipvlan_info_ops = {
143 .io_alloc = ipvlan_alloc,
144 .io_parse = ipvlan_parse,
149 .io_clone = ipvlan_clone,
150 .io_put_attrs = ipvlan_put_attrs,
151 .io_free = ipvlan_free,
155#define IS_IPVLAN_LINK_ASSERT(link) \
156 if ((link)->l_info_ops != &ipvlan_info_ops) { \
157 APPBUG("Link is not a ipvlan link. set type \"ipvlan\" first."); \
158 return -NLE_OPNOTSUPP; \
195 return link->l_info_ops && !strcmp(link->l_info_ops->io_name,
"ipvlan");
207 struct ipvlan_info *ipi = link->l_info;
209 IS_IPVLAN_LINK_ASSERT(link);
211 ipi->ipi_mode = mode;
212 ipi->ipi_mask |= IPVLAN_HAS_MODE;
226 struct ipvlan_info *ipi = link->l_info;
228 IS_IPVLAN_LINK_ASSERT(link);
230 if (!(ipi->ipi_mask & IPVLAN_HAS_MODE))
232 *out_mode = ipi->ipi_mode;
238static const struct trans_tbl ipvlan_modes[] = {
239 __ADD(IPVLAN_MODE_L2, l2),
240 __ADD(IPVLAN_MODE_L3, l3),
248char *rtnl_link_ipvlan_mode2str(
int mode,
char *buf,
size_t len)
250 return __type2str(mode, buf, len, ipvlan_modes, ARRAY_SIZE(ipvlan_modes));
253int rtnl_link_ipvlan_str2mode(
const char *name)
255 return __str2type(name, ipvlan_modes, ARRAY_SIZE(ipvlan_modes));
260static void __init ipvlan_init(
void)
265static void __exit ipvlan_exit(
void)
uint16_t nla_get_u16(const struct nlattr *nla)
Return payload of 16 bit integer attribute.
#define NLA_PUT_U16(msg, attrtype, value)
Add 16 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_ipvlan_set_mode(struct rtnl_link *link, uint16_t mode)
Set IPVLAN MODE.
int rtnl_link_ipvlan_get_mode(struct rtnl_link *link, uint16_t *out_mode)
Get IPVLAN Mode.
struct rtnl_link * rtnl_link_ipvlan_alloc(void)
Allocate link object of type IPVLAN.
int rtnl_link_is_ipvlan(struct rtnl_link *link)
Check if link is a IPVLAN link.
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.
Attribute validation policy.
uint16_t type
Type of attribute or NLA_UNSPEC.