14#include "nl-default.h"
16#include <netlink/route/link/bridge_info.h>
21#define BRIDGE_ATTR_VLAN_FILTERING (1 << 0)
22#define BRIDGE_ATTR_VLAN_PROTOCOL (1 << 1)
23#define BRIDGE_ATTR_VLAN_STATS_ENABLED (1 << 2)
27 uint16_t b_vlan_protocol;
28 uint8_t b_vlan_filtering;
29 uint8_t b_vlan_stats_enabled;
32static const struct nla_policy bi_attrs_policy[IFLA_BR_MAX + 1] = {
34 [IFLA_BR_VLAN_PROTOCOL] = { .type =
NLA_U16 },
35 [IFLA_BR_VLAN_STATS_ENABLED] = { .type =
NLA_U8 },
43static int bridge_info_alloc(
struct rtnl_link *link)
48 memset(link->l_info, 0,
sizeof(*bi));
50 bi = calloc(1,
sizeof(*bi));
60static int bridge_info_parse(
struct rtnl_link *link,
struct nlattr *data,
61 struct nlattr *xstats)
63 struct nlattr *tb[IFLA_BR_MAX + 1];
67 NL_DBG(3,
"Parsing Bridge link info\n");
73 if ((err = bridge_info_alloc(link)) < 0)
78 if (tb[IFLA_BR_VLAN_FILTERING]) {
79 bi->b_vlan_filtering =
nla_get_u8(tb[IFLA_BR_VLAN_FILTERING]);
80 bi->ce_mask |= BRIDGE_ATTR_VLAN_FILTERING;
83 if (tb[IFLA_BR_VLAN_PROTOCOL]) {
86 bi->ce_mask |= BRIDGE_ATTR_VLAN_PROTOCOL;
89 if (tb[IFLA_BR_VLAN_STATS_ENABLED]) {
90 bi->b_vlan_stats_enabled =
92 bi->ce_mask |= BRIDGE_ATTR_VLAN_STATS_ENABLED;
98static int bridge_info_put_attrs(
struct nl_msg *msg,
struct rtnl_link *link)
107 if (bi->ce_mask & BRIDGE_ATTR_VLAN_FILTERING)
108 NLA_PUT_U8(msg, IFLA_BR_VLAN_FILTERING, bi->b_vlan_filtering);
110 if (bi->ce_mask & BRIDGE_ATTR_VLAN_PROTOCOL)
112 htons(bi->b_vlan_protocol));
114 if (bi->ce_mask & BRIDGE_ATTR_VLAN_STATS_ENABLED)
116 bi->b_vlan_stats_enabled);
126static void bridge_info_free(
struct rtnl_link *link)
128 _nl_clear_free(&link->l_info);
133 .io_alloc = bridge_info_alloc,
134 .io_parse = bridge_info_parse,
135 .io_put_attrs = bridge_info_put_attrs,
136 .io_free = bridge_info_free,
139#define IS_BRIDGE_INFO_ASSERT(link) \
141 if ((link)->l_info_ops != &bridge_info_ops) { \
142 APPBUG("Link is not a bridge link. Set type \"bridge\" first."); \
156 uint8_t vlan_filtering)
160 IS_BRIDGE_INFO_ASSERT(link);
162 bi->b_vlan_filtering = vlan_filtering;
164 bi->ce_mask |= BRIDGE_ATTR_VLAN_FILTERING;
179 uint8_t *vlan_filtering)
183 IS_BRIDGE_INFO_ASSERT(link);
185 if (!(bi->ce_mask & BRIDGE_ATTR_VLAN_FILTERING))
191 *vlan_filtering = bi->b_vlan_filtering;
206 uint16_t vlan_protocol)
210 IS_BRIDGE_INFO_ASSERT(link);
212 bi->b_vlan_protocol = vlan_protocol;
214 bi->ce_mask |= BRIDGE_ATTR_VLAN_PROTOCOL;
229 uint16_t *vlan_protocol)
233 IS_BRIDGE_INFO_ASSERT(link);
235 if (!(bi->ce_mask & BRIDGE_ATTR_VLAN_PROTOCOL))
241 *vlan_protocol = bi->b_vlan_protocol;
256 uint8_t vlan_stats_enabled)
260 IS_BRIDGE_INFO_ASSERT(link);
262 bi->b_vlan_stats_enabled = vlan_stats_enabled;
264 bi->ce_mask |= BRIDGE_ATTR_VLAN_STATS_ENABLED;
279 uint8_t *vlan_stats_enabled)
283 IS_BRIDGE_INFO_ASSERT(link);
285 if (!(bi->ce_mask & BRIDGE_ATTR_VLAN_STATS_ENABLED))
288 if (!vlan_stats_enabled)
291 *vlan_stats_enabled = bi->b_vlan_stats_enabled;
296static void _nl_init bridge_info_init(
void)
301static void _nl_exit bridge_info_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.
#define NLA_PUT_U8(msg, attrtype, value)
Add 8 bit integer attribute to netlink message.
uint8_t nla_get_u8(const struct nlattr *nla)
Return value of 8 bit integer attribute.
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.
void nla_nest_cancel(struct nl_msg *msg, const struct nlattr *attr)
Cancel the addition of a nested attribute.
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes.
int rtnl_link_bridge_get_vlan_protocol(struct rtnl_link *link, uint16_t *vlan_protocol)
Get VLAN protocol.
void rtnl_link_bridge_set_vlan_stats_enabled(struct rtnl_link *link, uint8_t vlan_stats_enabled)
Set VLAN stats enabled flag.
void rtnl_link_bridge_set_vlan_filtering(struct rtnl_link *link, uint8_t vlan_filtering)
Set VLAN filtering flag.
int rtnl_link_bridge_get_vlan_filtering(struct rtnl_link *link, uint8_t *vlan_filtering)
Get VLAN filtering flag.
int rtnl_link_bridge_get_vlan_stats_enabled(struct rtnl_link *link, uint8_t *vlan_stats_enabled)
Get VLAN stats enabled flag.
void rtnl_link_bridge_set_vlan_protocol(struct rtnl_link *link, uint16_t vlan_protocol)
Set VLAN protocol.
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.
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.