xref: /openbmc/linux/include/net/rtnetlink.h (revision 3729d5021257b283f7fce33d957893162ccb2c9d)
1e2849863SThomas Graf #ifndef __NET_RTNETLINK_H
2e2849863SThomas Graf #define __NET_RTNETLINK_H
3e2849863SThomas Graf 
4e2849863SThomas Graf #include <linux/rtnetlink.h>
5e2849863SThomas Graf #include <net/netlink.h>
6e2849863SThomas Graf 
7e2849863SThomas Graf typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *, void *);
8e2849863SThomas Graf typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
9e2849863SThomas Graf 
10e2849863SThomas Graf extern int	__rtnl_register(int protocol, int msgtype,
11e2849863SThomas Graf 				rtnl_doit_func, rtnl_dumpit_func);
12e2849863SThomas Graf extern void	rtnl_register(int protocol, int msgtype,
13e2849863SThomas Graf 			      rtnl_doit_func, rtnl_dumpit_func);
14e2849863SThomas Graf extern int	rtnl_unregister(int protocol, int msgtype);
15e2849863SThomas Graf extern void	rtnl_unregister_all(int protocol);
16e2849863SThomas Graf 
173a6c2b41SPatrick McHardy static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
18c454673dSThomas Graf {
19c454673dSThomas Graf 	if (nlmsg_len(nlh) >= sizeof(struct rtgenmsg))
20c454673dSThomas Graf 		return ((struct rtgenmsg *) nlmsg_data(nlh))->rtgen_family;
21c454673dSThomas Graf 	else
22c454673dSThomas Graf 		return AF_UNSPEC;
23c454673dSThomas Graf }
24c454673dSThomas Graf 
2538f7b870SPatrick McHardy /**
2638f7b870SPatrick McHardy  *	struct rtnl_link_ops - rtnetlink link operations
2738f7b870SPatrick McHardy  *
2838f7b870SPatrick McHardy  *	@list: Used internally
2938f7b870SPatrick McHardy  *	@kind: Identifier
3038f7b870SPatrick McHardy  *	@maxtype: Highest device specific netlink attribute number
3138f7b870SPatrick McHardy  *	@policy: Netlink policy for device specific attribute validation
3238f7b870SPatrick McHardy  *	@validate: Optional validation function for netlink/changelink parameters
3338f7b870SPatrick McHardy  *	@priv_size: sizeof net_device private space
3438f7b870SPatrick McHardy  *	@setup: net_device setup function
3538f7b870SPatrick McHardy  *	@newlink: Function for configuring and registering a new device
3638f7b870SPatrick McHardy  *	@changelink: Function for changing parameters of an existing device
3738f7b870SPatrick McHardy  *	@dellink: Function to remove a device
3838f7b870SPatrick McHardy  *	@get_size: Function to calculate required room for dumping device
3938f7b870SPatrick McHardy  *		   specific netlink attributes
4038f7b870SPatrick McHardy  *	@fill_info: Function to dump device specific netlink attributes
4138f7b870SPatrick McHardy  *	@get_xstats_size: Function to calculate required room for dumping devic
4238f7b870SPatrick McHardy  *			  specific statistics
4338f7b870SPatrick McHardy  *	@fill_xstats: Function to dump device specific statistics
4438f7b870SPatrick McHardy  */
4538f7b870SPatrick McHardy struct rtnl_link_ops {
4638f7b870SPatrick McHardy 	struct list_head	list;
4738f7b870SPatrick McHardy 
4838f7b870SPatrick McHardy 	const char		*kind;
4938f7b870SPatrick McHardy 
5038f7b870SPatrick McHardy 	size_t			priv_size;
5138f7b870SPatrick McHardy 	void			(*setup)(struct net_device *dev);
5238f7b870SPatrick McHardy 
5338f7b870SPatrick McHardy 	int			maxtype;
5438f7b870SPatrick McHardy 	const struct nla_policy	*policy;
5538f7b870SPatrick McHardy 	int			(*validate)(struct nlattr *tb[],
5638f7b870SPatrick McHardy 					    struct nlattr *data[]);
5738f7b870SPatrick McHardy 
5881adee47SEric W. Biederman 	int			(*newlink)(struct net *src_net,
5981adee47SEric W. Biederman 					   struct net_device *dev,
6038f7b870SPatrick McHardy 					   struct nlattr *tb[],
6138f7b870SPatrick McHardy 					   struct nlattr *data[]);
6238f7b870SPatrick McHardy 	int			(*changelink)(struct net_device *dev,
6338f7b870SPatrick McHardy 					      struct nlattr *tb[],
6438f7b870SPatrick McHardy 					      struct nlattr *data[]);
6523289a37SEric Dumazet 	void			(*dellink)(struct net_device *dev,
6623289a37SEric Dumazet 					   struct list_head *head);
6738f7b870SPatrick McHardy 
6838f7b870SPatrick McHardy 	size_t			(*get_size)(const struct net_device *dev);
6938f7b870SPatrick McHardy 	int			(*fill_info)(struct sk_buff *skb,
7038f7b870SPatrick McHardy 					     const struct net_device *dev);
7138f7b870SPatrick McHardy 
7238f7b870SPatrick McHardy 	size_t			(*get_xstats_size)(const struct net_device *dev);
7338f7b870SPatrick McHardy 	int			(*fill_xstats)(struct sk_buff *skb,
7438f7b870SPatrick McHardy 					       const struct net_device *dev);
752e59af3dSEric Dumazet 	int			(*get_tx_queues)(struct net *net, struct nlattr *tb[],
762e59af3dSEric Dumazet 						 unsigned int *tx_queues,
772e59af3dSEric Dumazet 						 unsigned int *real_tx_queues);
7838f7b870SPatrick McHardy };
7938f7b870SPatrick McHardy 
8038f7b870SPatrick McHardy extern int	__rtnl_link_register(struct rtnl_link_ops *ops);
8138f7b870SPatrick McHardy extern void	__rtnl_link_unregister(struct rtnl_link_ops *ops);
82669f87baSPavel Emelyanov extern void	rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops);
8338f7b870SPatrick McHardy 
8438f7b870SPatrick McHardy extern int	rtnl_link_register(struct rtnl_link_ops *ops);
8538f7b870SPatrick McHardy extern void	rtnl_link_unregister(struct rtnl_link_ops *ops);
8638f7b870SPatrick McHardy 
8781adee47SEric W. Biederman extern struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
8881adee47SEric W. Biederman extern struct net_device *rtnl_create_link(struct net *src_net, struct net *net,
8981adee47SEric W. Biederman 	char *ifname, const struct rtnl_link_ops *ops, struct nlattr *tb[]);
90*3729d502SPatrick McHardy extern int rtnl_configure_link(struct net_device *dev,
91*3729d502SPatrick McHardy 			       const struct ifinfomsg *ifm);
92e7199288SPavel Emelianov extern const struct nla_policy ifla_policy[IFLA_MAX+1];
93e7199288SPavel Emelianov 
9438f7b870SPatrick McHardy #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
9538f7b870SPatrick McHardy 
96e2849863SThomas Graf #endif
97