17#include <netlink/route/link/ppp.h>
19#include <netlink-private/netlink.h>
20#include <netlink/netlink.h>
21#include <netlink-private/route/link/api.h>
24#define PPP_ATTR_FD (1<<0)
34static struct nla_policy ppp_nl_policy[IFLA_PPP_MAX+1] = {
35 [IFLA_PPP_DEV_FD] = { .
type = NLA_S32 },
38static int ppp_alloc(
struct rtnl_link *link)
40 struct ppp_info *info;
43 memset(link->l_info, 0,
sizeof(*info));
45 if ((info = calloc(1,
sizeof(*info))) == NULL)
54static int ppp_parse(
struct rtnl_link *link,
struct nlattr *data,
55 struct nlattr *xstats)
57 struct nlattr *tb[IFLA_PPP_MAX+1];
58 struct ppp_info *info;
61 NL_DBG(3,
"Parsing PPP link info\n");
66 if ((err = ppp_alloc(link)) < 0)
71 if (tb[IFLA_PPP_DEV_FD]) {
73 info->ce_mask |= PPP_ATTR_FD;
81static void ppp_free(
struct rtnl_link *link)
89 struct ppp_info *vdst, *vsrc = src->l_info;
100 memcpy(vdst, vsrc,
sizeof(
struct ppp_info));
105static int ppp_put_attrs(
struct nl_msg *msg,
struct rtnl_link *link)
107 struct ppp_info *info = link->l_info;
113 if (info->ce_mask & PPP_ATTR_FD)
123static struct rtnl_link_info_ops ppp_info_ops = {
125 .io_alloc = ppp_alloc,
126 .io_parse = ppp_parse,
127 .io_clone = ppp_clone,
128 .io_put_attrs = ppp_put_attrs,
133#define IS_PPP_LINK_ASSERT(link) \
134 if ((link)->l_info_ops != &ppp_info_ops) { \
135 APPBUG("Link is not a PPP link. set type \"ppp\" first."); \
136 return -NLE_OPNOTSUPP; \
174 struct ppp_info *info = link->l_info;
176 IS_PPP_LINK_ASSERT(link);
179 info->ce_mask |= PPP_ATTR_FD;
192 struct ppp_info *info = link->l_info;
194 IS_PPP_LINK_ASSERT(link);
196 if (!(info->ce_mask & PPP_ATTR_FD))
207static void __init ppp_init(
void)
212static void __exit ppp_exit(
void)
#define NLA_PUT_S32(msg, attrtype, value)
Add 32 bit signed 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.
int32_t nla_get_s32(const struct nlattr *nla)
Return payload of 32 bit signed integer 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.
int rtnl_link_ppp_get_fd(struct rtnl_link *link, int32_t *fd)
Get PPP file descriptor.
int rtnl_link_ppp_set_fd(struct rtnl_link *link, int32_t fd)
Set PPP file descriptor.
struct rtnl_link * rtnl_link_ppp_alloc(void)
Allocate link object of type PPP.
Attribute validation policy.
uint16_t type
Type of attribute or NLA_UNSPEC.