23 #include <netlink/route/link/ppp.h> 25 #include <netlink-private/netlink.h> 26 #include <netlink/netlink.h> 27 #include <netlink-private/route/link/api.h> 30 #define PPP_ATTR_FD (1<<0) 40 static struct nla_policy ppp_nl_policy[IFLA_PPP_MAX+1] = {
41 [IFLA_PPP_DEV_FD] = { .
type = NLA_S32 },
44 static int ppp_alloc(
struct rtnl_link *link)
46 struct ppp_info *info;
49 memset(link->l_info, 0,
sizeof(*info));
51 if ((info = calloc(1,
sizeof(*info))) == NULL)
60 static int ppp_parse(
struct rtnl_link *link,
struct nlattr *data,
61 struct nlattr *xstats)
63 struct nlattr *tb[IFLA_PPP_MAX+1];
64 struct ppp_info *info;
67 NL_DBG(3,
"Parsing PPP link info\n");
72 if ((err = ppp_alloc(link)) < 0)
77 if (tb[IFLA_PPP_DEV_FD]) {
79 info->ce_mask |= PPP_ATTR_FD;
87 static void ppp_free(
struct rtnl_link *link)
95 struct ppp_info *vdst, *vsrc = src->l_info;
106 memcpy(vdst, vsrc,
sizeof(
struct ppp_info));
111 static int ppp_put_attrs(
struct nl_msg *msg,
struct rtnl_link *link)
113 struct ppp_info *info = link->l_info;
119 if (info->ce_mask & PPP_ATTR_FD)
129 static struct rtnl_link_info_ops ppp_info_ops = {
131 .io_alloc = ppp_alloc,
132 .io_parse = ppp_parse,
133 .io_clone = ppp_clone,
134 .io_put_attrs = ppp_put_attrs,
139 #define IS_PPP_LINK_ASSERT(link) \ 140 if ((link)->l_info_ops != &ppp_info_ops) { \ 141 APPBUG("Link is not a PPP link. set type \"ppp\" first."); \ 142 return -NLE_OPNOTSUPP; \ 181 struct ppp_info *info = link->l_info;
183 IS_PPP_LINK_ASSERT(link);
186 info->ce_mask |= PPP_ATTR_FD;
199 struct ppp_info *info = link->l_info;
201 IS_PPP_LINK_ASSERT(link);
203 if (!(info->ce_mask & PPP_ATTR_FD))
214 static void __init ppp_init(
void)
219 static void __exit ppp_exit(
void)
int32_t nla_get_s32(const struct nlattr *nla)
Return payload of 32 bit signed integer attribute.
int rtnl_link_register_info(struct rtnl_link_info_ops *ops)
Register operations for a link info type.
Attribute validation policy.
struct rtnl_link * rtnl_link_alloc(void)
Allocate link object.
int rtnl_link_ppp_get_fd(struct rtnl_link *link, int32_t *fd)
Get PPP file descriptor.
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, struct nla_policy *policy)
Create attribute index based on nested attribute.
int rtnl_link_set_type(struct rtnl_link *link, const char *type)
Set type of link object.
int rtnl_link_ppp_set_fd(struct rtnl_link *link, int32_t fd)
Set PPP file descriptor.
int rtnl_link_unregister_info(struct rtnl_link_info_ops *ops)
Unregister operations for a link info type.
uint16_t type
Type of attribute or NLA_UNSPEC.
struct rtnl_link * rtnl_link_ppp_alloc(void)
Allocate link object of type PPP.
void rtnl_link_put(struct rtnl_link *link)
Return a link object reference.
#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.