xref: /openbmc/linux/include/net/rtnetlink.h (revision 115c9b81928360d769a76c632bae62d15206a94a)
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 *);
9*115c9b81SGreg Rose typedef u16 (*rtnl_calcit_func)(struct sk_buff *, struct nlmsghdr *);
10e2849863SThomas Graf 
11e2849863SThomas Graf extern int	__rtnl_register(int protocol, int msgtype,
12c7ac8679SGreg Rose 				rtnl_doit_func, rtnl_dumpit_func,
13c7ac8679SGreg Rose 				rtnl_calcit_func);
14e2849863SThomas Graf extern void	rtnl_register(int protocol, int msgtype,
15c7ac8679SGreg Rose 			      rtnl_doit_func, rtnl_dumpit_func,
16c7ac8679SGreg Rose 			      rtnl_calcit_func);
17e2849863SThomas Graf extern int	rtnl_unregister(int protocol, int msgtype);
18e2849863SThomas Graf extern void	rtnl_unregister_all(int protocol);
19e2849863SThomas Graf 
203a6c2b41SPatrick McHardy static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
21c454673dSThomas Graf {
22c454673dSThomas Graf 	if (nlmsg_len(nlh) >= sizeof(struct rtgenmsg))
23c454673dSThomas Graf 		return ((struct rtgenmsg *) nlmsg_data(nlh))->rtgen_family;
24c454673dSThomas Graf 	else
25c454673dSThomas Graf 		return AF_UNSPEC;
26c454673dSThomas Graf }
27c454673dSThomas Graf 
2838f7b870SPatrick McHardy /**
2938f7b870SPatrick McHardy  *	struct rtnl_link_ops - rtnetlink link operations
3038f7b870SPatrick McHardy  *
3138f7b870SPatrick McHardy  *	@list: Used internally
3238f7b870SPatrick McHardy  *	@kind: Identifier
3338f7b870SPatrick McHardy  *	@maxtype: Highest device specific netlink attribute number
3438f7b870SPatrick McHardy  *	@policy: Netlink policy for device specific attribute validation
3538f7b870SPatrick McHardy  *	@validate: Optional validation function for netlink/changelink parameters
3638f7b870SPatrick McHardy  *	@priv_size: sizeof net_device private space
3738f7b870SPatrick McHardy  *	@setup: net_device setup function
3838f7b870SPatrick McHardy  *	@newlink: Function for configuring and registering a new device
3938f7b870SPatrick McHardy  *	@changelink: Function for changing parameters of an existing device
4038f7b870SPatrick McHardy  *	@dellink: Function to remove a device
4138f7b870SPatrick McHardy  *	@get_size: Function to calculate required room for dumping device
4238f7b870SPatrick McHardy  *		   specific netlink attributes
4338f7b870SPatrick McHardy  *	@fill_info: Function to dump device specific netlink attributes
4438f7b870SPatrick McHardy  *	@get_xstats_size: Function to calculate required room for dumping devic
4538f7b870SPatrick McHardy  *			  specific statistics
4638f7b870SPatrick McHardy  *	@fill_xstats: Function to dump device specific statistics
4738f7b870SPatrick McHardy  */
4838f7b870SPatrick McHardy struct rtnl_link_ops {
4938f7b870SPatrick McHardy 	struct list_head	list;
5038f7b870SPatrick McHardy 
5138f7b870SPatrick McHardy 	const char		*kind;
5238f7b870SPatrick McHardy 
5338f7b870SPatrick McHardy 	size_t			priv_size;
5438f7b870SPatrick McHardy 	void			(*setup)(struct net_device *dev);
5538f7b870SPatrick McHardy 
5638f7b870SPatrick McHardy 	int			maxtype;
5738f7b870SPatrick McHardy 	const struct nla_policy	*policy;
5838f7b870SPatrick McHardy 	int			(*validate)(struct nlattr *tb[],
5938f7b870SPatrick McHardy 					    struct nlattr *data[]);
6038f7b870SPatrick McHardy 
6181adee47SEric W. Biederman 	int			(*newlink)(struct net *src_net,
6281adee47SEric W. Biederman 					   struct net_device *dev,
6338f7b870SPatrick McHardy 					   struct nlattr *tb[],
6438f7b870SPatrick McHardy 					   struct nlattr *data[]);
6538f7b870SPatrick McHardy 	int			(*changelink)(struct net_device *dev,
6638f7b870SPatrick McHardy 					      struct nlattr *tb[],
6738f7b870SPatrick McHardy 					      struct nlattr *data[]);
6823289a37SEric Dumazet 	void			(*dellink)(struct net_device *dev,
6923289a37SEric Dumazet 					   struct list_head *head);
7038f7b870SPatrick McHardy 
7138f7b870SPatrick McHardy 	size_t			(*get_size)(const struct net_device *dev);
7238f7b870SPatrick McHardy 	int			(*fill_info)(struct sk_buff *skb,
7338f7b870SPatrick McHardy 					     const struct net_device *dev);
7438f7b870SPatrick McHardy 
7538f7b870SPatrick McHardy 	size_t			(*get_xstats_size)(const struct net_device *dev);
7638f7b870SPatrick McHardy 	int			(*fill_xstats)(struct sk_buff *skb,
7738f7b870SPatrick McHardy 					       const struct net_device *dev);
782e59af3dSEric Dumazet 	int			(*get_tx_queues)(struct net *net, struct nlattr *tb[],
792e59af3dSEric Dumazet 						 unsigned int *tx_queues,
802e59af3dSEric Dumazet 						 unsigned int *real_tx_queues);
8138f7b870SPatrick McHardy };
8238f7b870SPatrick McHardy 
8338f7b870SPatrick McHardy extern int	__rtnl_link_register(struct rtnl_link_ops *ops);
8438f7b870SPatrick McHardy extern void	__rtnl_link_unregister(struct rtnl_link_ops *ops);
8538f7b870SPatrick McHardy 
8638f7b870SPatrick McHardy extern int	rtnl_link_register(struct rtnl_link_ops *ops);
8738f7b870SPatrick McHardy extern void	rtnl_link_unregister(struct rtnl_link_ops *ops);
8838f7b870SPatrick McHardy 
89f8ff182cSThomas Graf /**
90f8ff182cSThomas Graf  * 	struct rtnl_af_ops - rtnetlink address family operations
91f8ff182cSThomas Graf  *
92f8ff182cSThomas Graf  *	@list: Used internally
93f8ff182cSThomas Graf  * 	@family: Address family
94f8ff182cSThomas Graf  * 	@fill_link_af: Function to fill IFLA_AF_SPEC with address family
95f8ff182cSThomas Graf  * 		       specific netlink attributes.
96f8ff182cSThomas Graf  * 	@get_link_af_size: Function to calculate size of address family specific
97f8ff182cSThomas Graf  * 			   netlink attributes exlusive the container attribute.
98cf7afbfeSThomas Graf  *	@validate_link_af: Validate a IFLA_AF_SPEC attribute, must check attr
99cf7afbfeSThomas Graf  *			   for invalid configuration settings.
100cf7afbfeSThomas Graf  * 	@set_link_af: Function to parse a IFLA_AF_SPEC attribute and modify
101f8ff182cSThomas Graf  *		      net_device accordingly.
102f8ff182cSThomas Graf  */
103f8ff182cSThomas Graf struct rtnl_af_ops {
104f8ff182cSThomas Graf 	struct list_head	list;
105f8ff182cSThomas Graf 	int			family;
106f8ff182cSThomas Graf 
107f8ff182cSThomas Graf 	int			(*fill_link_af)(struct sk_buff *skb,
108f8ff182cSThomas Graf 						const struct net_device *dev);
109f8ff182cSThomas Graf 	size_t			(*get_link_af_size)(const struct net_device *dev);
110f8ff182cSThomas Graf 
111cf7afbfeSThomas Graf 	int			(*validate_link_af)(const struct net_device *dev,
112cf7afbfeSThomas Graf 						    const struct nlattr *attr);
113cf7afbfeSThomas Graf 	int			(*set_link_af)(struct net_device *dev,
114f8ff182cSThomas Graf 					       const struct nlattr *attr);
115f8ff182cSThomas Graf };
116f8ff182cSThomas Graf 
117f8ff182cSThomas Graf extern int	__rtnl_af_register(struct rtnl_af_ops *ops);
118f8ff182cSThomas Graf extern void	__rtnl_af_unregister(struct rtnl_af_ops *ops);
119f8ff182cSThomas Graf 
120f8ff182cSThomas Graf extern int	rtnl_af_register(struct rtnl_af_ops *ops);
121f8ff182cSThomas Graf extern void	rtnl_af_unregister(struct rtnl_af_ops *ops);
122f8ff182cSThomas Graf 
123f8ff182cSThomas Graf 
12481adee47SEric W. Biederman extern struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
12581adee47SEric W. Biederman extern struct net_device *rtnl_create_link(struct net *src_net, struct net *net,
12681adee47SEric W. Biederman 	char *ifname, const struct rtnl_link_ops *ops, struct nlattr *tb[]);
1273729d502SPatrick McHardy extern int rtnl_configure_link(struct net_device *dev,
1283729d502SPatrick McHardy 			       const struct ifinfomsg *ifm);
129e7199288SPavel Emelianov extern const struct nla_policy ifla_policy[IFLA_MAX+1];
130e7199288SPavel Emelianov 
13138f7b870SPatrick McHardy #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
13238f7b870SPatrick McHardy 
133e2849863SThomas Graf #endif
134