18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __NET_RTNETLINK_H
38c2ecf20Sopenharmony_ci#define __NET_RTNETLINK_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/rtnetlink.h>
68c2ecf20Sopenharmony_ci#include <net/netlink.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_citypedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *,
98c2ecf20Sopenharmony_ci			      struct netlink_ext_ack *);
108c2ecf20Sopenharmony_citypedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cienum rtnl_link_flags {
138c2ecf20Sopenharmony_ci	RTNL_FLAG_DOIT_UNLOCKED = 1,
148c2ecf20Sopenharmony_ci};
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_civoid rtnl_register(int protocol, int msgtype,
178c2ecf20Sopenharmony_ci		   rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
188c2ecf20Sopenharmony_ciint rtnl_register_module(struct module *owner, int protocol, int msgtype,
198c2ecf20Sopenharmony_ci			 rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
208c2ecf20Sopenharmony_ciint rtnl_unregister(int protocol, int msgtype);
218c2ecf20Sopenharmony_civoid rtnl_unregister_all(int protocol);
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic inline int rtnl_msg_family(const struct nlmsghdr *nlh)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	if (nlmsg_len(nlh) >= sizeof(struct rtgenmsg))
268c2ecf20Sopenharmony_ci		return ((struct rtgenmsg *) nlmsg_data(nlh))->rtgen_family;
278c2ecf20Sopenharmony_ci	else
288c2ecf20Sopenharmony_ci		return AF_UNSPEC;
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/**
328c2ecf20Sopenharmony_ci *	struct rtnl_link_ops - rtnetlink link operations
338c2ecf20Sopenharmony_ci *
348c2ecf20Sopenharmony_ci *	@list: Used internally
358c2ecf20Sopenharmony_ci *	@kind: Identifier
368c2ecf20Sopenharmony_ci *	@netns_refund: Physical device, move to init_net on netns exit
378c2ecf20Sopenharmony_ci *	@maxtype: Highest device specific netlink attribute number
388c2ecf20Sopenharmony_ci *	@policy: Netlink policy for device specific attribute validation
398c2ecf20Sopenharmony_ci *	@validate: Optional validation function for netlink/changelink parameters
408c2ecf20Sopenharmony_ci *	@priv_size: sizeof net_device private space
418c2ecf20Sopenharmony_ci *	@setup: net_device setup function
428c2ecf20Sopenharmony_ci *	@newlink: Function for configuring and registering a new device
438c2ecf20Sopenharmony_ci *	@changelink: Function for changing parameters of an existing device
448c2ecf20Sopenharmony_ci *	@dellink: Function to remove a device
458c2ecf20Sopenharmony_ci *	@get_size: Function to calculate required room for dumping device
468c2ecf20Sopenharmony_ci *		   specific netlink attributes
478c2ecf20Sopenharmony_ci *	@fill_info: Function to dump device specific netlink attributes
488c2ecf20Sopenharmony_ci *	@get_xstats_size: Function to calculate required room for dumping device
498c2ecf20Sopenharmony_ci *			  specific statistics
508c2ecf20Sopenharmony_ci *	@fill_xstats: Function to dump device specific statistics
518c2ecf20Sopenharmony_ci *	@get_num_tx_queues: Function to determine number of transmit queues
528c2ecf20Sopenharmony_ci *			    to create when creating a new device.
538c2ecf20Sopenharmony_ci *	@get_num_rx_queues: Function to determine number of receive queues
548c2ecf20Sopenharmony_ci *			    to create when creating a new device.
558c2ecf20Sopenharmony_ci *	@get_link_net: Function to get the i/o netns of the device
568c2ecf20Sopenharmony_ci *	@get_linkxstats_size: Function to calculate the required room for
578c2ecf20Sopenharmony_ci *			      dumping device-specific extended link stats
588c2ecf20Sopenharmony_ci *	@fill_linkxstats: Function to dump device-specific extended link stats
598c2ecf20Sopenharmony_ci */
608c2ecf20Sopenharmony_cistruct rtnl_link_ops {
618c2ecf20Sopenharmony_ci	struct list_head	list;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	const char		*kind;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	size_t			priv_size;
668c2ecf20Sopenharmony_ci	void			(*setup)(struct net_device *dev);
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	bool			netns_refund;
698c2ecf20Sopenharmony_ci	unsigned int		maxtype;
708c2ecf20Sopenharmony_ci	const struct nla_policy	*policy;
718c2ecf20Sopenharmony_ci	int			(*validate)(struct nlattr *tb[],
728c2ecf20Sopenharmony_ci					    struct nlattr *data[],
738c2ecf20Sopenharmony_ci					    struct netlink_ext_ack *extack);
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	int			(*newlink)(struct net *src_net,
768c2ecf20Sopenharmony_ci					   struct net_device *dev,
778c2ecf20Sopenharmony_ci					   struct nlattr *tb[],
788c2ecf20Sopenharmony_ci					   struct nlattr *data[],
798c2ecf20Sopenharmony_ci					   struct netlink_ext_ack *extack);
808c2ecf20Sopenharmony_ci	int			(*changelink)(struct net_device *dev,
818c2ecf20Sopenharmony_ci					      struct nlattr *tb[],
828c2ecf20Sopenharmony_ci					      struct nlattr *data[],
838c2ecf20Sopenharmony_ci					      struct netlink_ext_ack *extack);
848c2ecf20Sopenharmony_ci	void			(*dellink)(struct net_device *dev,
858c2ecf20Sopenharmony_ci					   struct list_head *head);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	size_t			(*get_size)(const struct net_device *dev);
888c2ecf20Sopenharmony_ci	int			(*fill_info)(struct sk_buff *skb,
898c2ecf20Sopenharmony_ci					     const struct net_device *dev);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	size_t			(*get_xstats_size)(const struct net_device *dev);
928c2ecf20Sopenharmony_ci	int			(*fill_xstats)(struct sk_buff *skb,
938c2ecf20Sopenharmony_ci					       const struct net_device *dev);
948c2ecf20Sopenharmony_ci	unsigned int		(*get_num_tx_queues)(void);
958c2ecf20Sopenharmony_ci	unsigned int		(*get_num_rx_queues)(void);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	unsigned int		slave_maxtype;
988c2ecf20Sopenharmony_ci	const struct nla_policy	*slave_policy;
998c2ecf20Sopenharmony_ci	int			(*slave_changelink)(struct net_device *dev,
1008c2ecf20Sopenharmony_ci						    struct net_device *slave_dev,
1018c2ecf20Sopenharmony_ci						    struct nlattr *tb[],
1028c2ecf20Sopenharmony_ci						    struct nlattr *data[],
1038c2ecf20Sopenharmony_ci						    struct netlink_ext_ack *extack);
1048c2ecf20Sopenharmony_ci	size_t			(*get_slave_size)(const struct net_device *dev,
1058c2ecf20Sopenharmony_ci						  const struct net_device *slave_dev);
1068c2ecf20Sopenharmony_ci	int			(*fill_slave_info)(struct sk_buff *skb,
1078c2ecf20Sopenharmony_ci						   const struct net_device *dev,
1088c2ecf20Sopenharmony_ci						   const struct net_device *slave_dev);
1098c2ecf20Sopenharmony_ci	struct net		*(*get_link_net)(const struct net_device *dev);
1108c2ecf20Sopenharmony_ci	size_t			(*get_linkxstats_size)(const struct net_device *dev,
1118c2ecf20Sopenharmony_ci						       int attr);
1128c2ecf20Sopenharmony_ci	int			(*fill_linkxstats)(struct sk_buff *skb,
1138c2ecf20Sopenharmony_ci						   const struct net_device *dev,
1148c2ecf20Sopenharmony_ci						   int *prividx, int attr);
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ciint __rtnl_link_register(struct rtnl_link_ops *ops);
1188c2ecf20Sopenharmony_civoid __rtnl_link_unregister(struct rtnl_link_ops *ops);
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ciint rtnl_link_register(struct rtnl_link_ops *ops);
1218c2ecf20Sopenharmony_civoid rtnl_link_unregister(struct rtnl_link_ops *ops);
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci/**
1248c2ecf20Sopenharmony_ci * 	struct rtnl_af_ops - rtnetlink address family operations
1258c2ecf20Sopenharmony_ci *
1268c2ecf20Sopenharmony_ci *	@list: Used internally
1278c2ecf20Sopenharmony_ci * 	@family: Address family
1288c2ecf20Sopenharmony_ci * 	@fill_link_af: Function to fill IFLA_AF_SPEC with address family
1298c2ecf20Sopenharmony_ci * 		       specific netlink attributes.
1308c2ecf20Sopenharmony_ci * 	@get_link_af_size: Function to calculate size of address family specific
1318c2ecf20Sopenharmony_ci * 			   netlink attributes.
1328c2ecf20Sopenharmony_ci *	@validate_link_af: Validate a IFLA_AF_SPEC attribute, must check attr
1338c2ecf20Sopenharmony_ci *			   for invalid configuration settings.
1348c2ecf20Sopenharmony_ci * 	@set_link_af: Function to parse a IFLA_AF_SPEC attribute and modify
1358c2ecf20Sopenharmony_ci *		      net_device accordingly.
1368c2ecf20Sopenharmony_ci */
1378c2ecf20Sopenharmony_cistruct rtnl_af_ops {
1388c2ecf20Sopenharmony_ci	struct list_head	list;
1398c2ecf20Sopenharmony_ci	int			family;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	int			(*fill_link_af)(struct sk_buff *skb,
1428c2ecf20Sopenharmony_ci						const struct net_device *dev,
1438c2ecf20Sopenharmony_ci						u32 ext_filter_mask);
1448c2ecf20Sopenharmony_ci	size_t			(*get_link_af_size)(const struct net_device *dev,
1458c2ecf20Sopenharmony_ci						    u32 ext_filter_mask);
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	int			(*validate_link_af)(const struct net_device *dev,
1488c2ecf20Sopenharmony_ci						    const struct nlattr *attr);
1498c2ecf20Sopenharmony_ci	int			(*set_link_af)(struct net_device *dev,
1508c2ecf20Sopenharmony_ci					       const struct nlattr *attr);
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	int			(*fill_stats_af)(struct sk_buff *skb,
1538c2ecf20Sopenharmony_ci						 const struct net_device *dev);
1548c2ecf20Sopenharmony_ci	size_t			(*get_stats_af_size)(const struct net_device *dev);
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_civoid rtnl_af_register(struct rtnl_af_ops *ops);
1588c2ecf20Sopenharmony_civoid rtnl_af_unregister(struct rtnl_af_ops *ops);
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistruct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
1618c2ecf20Sopenharmony_cistruct net_device *rtnl_create_link(struct net *net, const char *ifname,
1628c2ecf20Sopenharmony_ci				    unsigned char name_assign_type,
1638c2ecf20Sopenharmony_ci				    const struct rtnl_link_ops *ops,
1648c2ecf20Sopenharmony_ci				    struct nlattr *tb[],
1658c2ecf20Sopenharmony_ci				    struct netlink_ext_ack *extack);
1668c2ecf20Sopenharmony_ciint rtnl_delete_link(struct net_device *dev);
1678c2ecf20Sopenharmony_ciint rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ciint rtnl_nla_parse_ifinfomsg(struct nlattr **tb, const struct nlattr *nla_peer,
1708c2ecf20Sopenharmony_ci			     struct netlink_ext_ack *exterr);
1718c2ecf20Sopenharmony_cistruct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci#endif
176