xref: /openbmc/linux/include/net/rtnetlink.h (revision c21ef3e343ae916ad3cfd4dc6ef6791c1f80a010)
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 
7*c21ef3e3SDavid Ahern typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *,
8*c21ef3e3SDavid Ahern 			      struct netlink_ext_ack *);
9e2849863SThomas Graf typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
10115c9b81SGreg Rose typedef u16 (*rtnl_calcit_func)(struct sk_buff *, struct nlmsghdr *);
11e2849863SThomas Graf 
12efb48ccfSJoe Perches int __rtnl_register(int protocol, int msgtype,
13efb48ccfSJoe Perches 		    rtnl_doit_func, rtnl_dumpit_func, rtnl_calcit_func);
14efb48ccfSJoe Perches void rtnl_register(int protocol, int msgtype,
15efb48ccfSJoe Perches 		   rtnl_doit_func, rtnl_dumpit_func, rtnl_calcit_func);
16efb48ccfSJoe Perches int rtnl_unregister(int protocol, int msgtype);
17efb48ccfSJoe Perches void rtnl_unregister_all(int protocol);
18e2849863SThomas Graf 
193a6c2b41SPatrick McHardy static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
20c454673dSThomas Graf {
21c454673dSThomas Graf 	if (nlmsg_len(nlh) >= sizeof(struct rtgenmsg))
22c454673dSThomas Graf 		return ((struct rtgenmsg *) nlmsg_data(nlh))->rtgen_family;
23c454673dSThomas Graf 	else
24c454673dSThomas Graf 		return AF_UNSPEC;
25c454673dSThomas Graf }
26c454673dSThomas Graf 
2738f7b870SPatrick McHardy /**
2838f7b870SPatrick McHardy  *	struct rtnl_link_ops - rtnetlink link operations
2938f7b870SPatrick McHardy  *
3038f7b870SPatrick McHardy  *	@list: Used internally
3138f7b870SPatrick McHardy  *	@kind: Identifier
3238f7b870SPatrick McHardy  *	@maxtype: Highest device specific netlink attribute number
3338f7b870SPatrick McHardy  *	@policy: Netlink policy for device specific attribute validation
3438f7b870SPatrick McHardy  *	@validate: Optional validation function for netlink/changelink parameters
3538f7b870SPatrick McHardy  *	@priv_size: sizeof net_device private space
3638f7b870SPatrick McHardy  *	@setup: net_device setup function
3738f7b870SPatrick McHardy  *	@newlink: Function for configuring and registering a new device
3838f7b870SPatrick McHardy  *	@changelink: Function for changing parameters of an existing device
3938f7b870SPatrick McHardy  *	@dellink: Function to remove a device
4038f7b870SPatrick McHardy  *	@get_size: Function to calculate required room for dumping device
4138f7b870SPatrick McHardy  *		   specific netlink attributes
4238f7b870SPatrick McHardy  *	@fill_info: Function to dump device specific netlink attributes
439b17876fSstephen hemminger  *	@get_xstats_size: Function to calculate required room for dumping device
4438f7b870SPatrick McHardy  *			  specific statistics
4538f7b870SPatrick McHardy  *	@fill_xstats: Function to dump device specific statistics
46d40156aaSJiri Pirko  *	@get_num_tx_queues: Function to determine number of transmit queues
47d40156aaSJiri Pirko  *			    to create when creating a new device.
48d40156aaSJiri Pirko  *	@get_num_rx_queues: Function to determine number of receive queues
49d40156aaSJiri Pirko  *			    to create when creating a new device.
50d37512a2SNicolas Dichtel  *	@get_link_net: Function to get the i/o netns of the device
5197a47facSNikolay Aleksandrov  *	@get_linkxstats_size: Function to calculate the required room for
5297a47facSNikolay Aleksandrov  *			      dumping device-specific extended link stats
5397a47facSNikolay Aleksandrov  *	@fill_linkxstats: Function to dump device-specific extended link stats
5438f7b870SPatrick McHardy  */
5538f7b870SPatrick McHardy struct rtnl_link_ops {
5638f7b870SPatrick McHardy 	struct list_head	list;
5738f7b870SPatrick McHardy 
5838f7b870SPatrick McHardy 	const char		*kind;
5938f7b870SPatrick McHardy 
6038f7b870SPatrick McHardy 	size_t			priv_size;
6138f7b870SPatrick McHardy 	void			(*setup)(struct net_device *dev);
6238f7b870SPatrick McHardy 
6338f7b870SPatrick McHardy 	int			maxtype;
6438f7b870SPatrick McHardy 	const struct nla_policy	*policy;
6538f7b870SPatrick McHardy 	int			(*validate)(struct nlattr *tb[],
6638f7b870SPatrick McHardy 					    struct nlattr *data[]);
6738f7b870SPatrick McHardy 
6881adee47SEric W. Biederman 	int			(*newlink)(struct net *src_net,
6981adee47SEric W. Biederman 					   struct net_device *dev,
7038f7b870SPatrick McHardy 					   struct nlattr *tb[],
7138f7b870SPatrick McHardy 					   struct nlattr *data[]);
7238f7b870SPatrick McHardy 	int			(*changelink)(struct net_device *dev,
7338f7b870SPatrick McHardy 					      struct nlattr *tb[],
7438f7b870SPatrick McHardy 					      struct nlattr *data[]);
7523289a37SEric Dumazet 	void			(*dellink)(struct net_device *dev,
7623289a37SEric Dumazet 					   struct list_head *head);
7738f7b870SPatrick McHardy 
7838f7b870SPatrick McHardy 	size_t			(*get_size)(const struct net_device *dev);
7938f7b870SPatrick McHardy 	int			(*fill_info)(struct sk_buff *skb,
8038f7b870SPatrick McHardy 					     const struct net_device *dev);
8138f7b870SPatrick McHardy 
8238f7b870SPatrick McHardy 	size_t			(*get_xstats_size)(const struct net_device *dev);
8338f7b870SPatrick McHardy 	int			(*fill_xstats)(struct sk_buff *skb,
8438f7b870SPatrick McHardy 					       const struct net_device *dev);
85d40156aaSJiri Pirko 	unsigned int		(*get_num_tx_queues)(void);
86d40156aaSJiri Pirko 	unsigned int		(*get_num_rx_queues)(void);
87ba7d49b1SJiri Pirko 
88ba7d49b1SJiri Pirko 	int			slave_maxtype;
89ba7d49b1SJiri Pirko 	const struct nla_policy	*slave_policy;
90ba7d49b1SJiri Pirko 	int			(*slave_validate)(struct nlattr *tb[],
91ba7d49b1SJiri Pirko 						  struct nlattr *data[]);
92ba7d49b1SJiri Pirko 	int			(*slave_changelink)(struct net_device *dev,
93ba7d49b1SJiri Pirko 						    struct net_device *slave_dev,
94ba7d49b1SJiri Pirko 						    struct nlattr *tb[],
95ba7d49b1SJiri Pirko 						    struct nlattr *data[]);
96ba7d49b1SJiri Pirko 	size_t			(*get_slave_size)(const struct net_device *dev,
97ba7d49b1SJiri Pirko 						  const struct net_device *slave_dev);
98ba7d49b1SJiri Pirko 	int			(*fill_slave_info)(struct sk_buff *skb,
99ba7d49b1SJiri Pirko 						   const struct net_device *dev,
100ba7d49b1SJiri Pirko 						   const struct net_device *slave_dev);
101d37512a2SNicolas Dichtel 	struct net		*(*get_link_net)(const struct net_device *dev);
10280e73cc5SNikolay Aleksandrov 	size_t			(*get_linkxstats_size)(const struct net_device *dev,
10380e73cc5SNikolay Aleksandrov 						       int attr);
10497a47facSNikolay Aleksandrov 	int			(*fill_linkxstats)(struct sk_buff *skb,
10597a47facSNikolay Aleksandrov 						   const struct net_device *dev,
10680e73cc5SNikolay Aleksandrov 						   int *prividx, int attr);
10738f7b870SPatrick McHardy };
10838f7b870SPatrick McHardy 
109efb48ccfSJoe Perches int __rtnl_link_register(struct rtnl_link_ops *ops);
110efb48ccfSJoe Perches void __rtnl_link_unregister(struct rtnl_link_ops *ops);
11138f7b870SPatrick McHardy 
112efb48ccfSJoe Perches int rtnl_link_register(struct rtnl_link_ops *ops);
113efb48ccfSJoe Perches void rtnl_link_unregister(struct rtnl_link_ops *ops);
11438f7b870SPatrick McHardy 
115f8ff182cSThomas Graf /**
116f8ff182cSThomas Graf  * 	struct rtnl_af_ops - rtnetlink address family operations
117f8ff182cSThomas Graf  *
118f8ff182cSThomas Graf  *	@list: Used internally
119f8ff182cSThomas Graf  * 	@family: Address family
120f8ff182cSThomas Graf  * 	@fill_link_af: Function to fill IFLA_AF_SPEC with address family
121f8ff182cSThomas Graf  * 		       specific netlink attributes.
122f8ff182cSThomas Graf  * 	@get_link_af_size: Function to calculate size of address family specific
1239b17876fSstephen hemminger  * 			   netlink attributes.
124cf7afbfeSThomas Graf  *	@validate_link_af: Validate a IFLA_AF_SPEC attribute, must check attr
125cf7afbfeSThomas Graf  *			   for invalid configuration settings.
126cf7afbfeSThomas Graf  * 	@set_link_af: Function to parse a IFLA_AF_SPEC attribute and modify
127f8ff182cSThomas Graf  *		      net_device accordingly.
128f8ff182cSThomas Graf  */
129f8ff182cSThomas Graf struct rtnl_af_ops {
130f8ff182cSThomas Graf 	struct list_head	list;
131f8ff182cSThomas Graf 	int			family;
132f8ff182cSThomas Graf 
133f8ff182cSThomas Graf 	int			(*fill_link_af)(struct sk_buff *skb,
134d5566fd7SSowmini Varadhan 						const struct net_device *dev,
135d5566fd7SSowmini Varadhan 						u32 ext_filter_mask);
136b1974ed0SArad, Ronen 	size_t			(*get_link_af_size)(const struct net_device *dev,
137b1974ed0SArad, Ronen 						    u32 ext_filter_mask);
138f8ff182cSThomas Graf 
139cf7afbfeSThomas Graf 	int			(*validate_link_af)(const struct net_device *dev,
140cf7afbfeSThomas Graf 						    const struct nlattr *attr);
141cf7afbfeSThomas Graf 	int			(*set_link_af)(struct net_device *dev,
142f8ff182cSThomas Graf 					       const struct nlattr *attr);
143aefb4d4aSRobert Shearman 
144aefb4d4aSRobert Shearman 	int			(*fill_stats_af)(struct sk_buff *skb,
145aefb4d4aSRobert Shearman 						 const struct net_device *dev);
146aefb4d4aSRobert Shearman 	size_t			(*get_stats_af_size)(const struct net_device *dev);
147f8ff182cSThomas Graf };
148f8ff182cSThomas Graf 
149efb48ccfSJoe Perches void __rtnl_af_unregister(struct rtnl_af_ops *ops);
150f8ff182cSThomas Graf 
1513678a9d8Sstephen hemminger void rtnl_af_register(struct rtnl_af_ops *ops);
152efb48ccfSJoe Perches void rtnl_af_unregister(struct rtnl_af_ops *ops);
153f8ff182cSThomas Graf 
154efb48ccfSJoe Perches struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
15578ebb0d0SThomas Graf struct net_device *rtnl_create_link(struct net *net, const char *ifname,
1565517750fSTom Gundersen 				    unsigned char name_assign_type,
157efb48ccfSJoe Perches 				    const struct rtnl_link_ops *ops,
158efb48ccfSJoe Perches 				    struct nlattr *tb[]);
159614732eaSThomas Graf int rtnl_delete_link(struct net_device *dev);
160efb48ccfSJoe Perches int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm);
161f8ff182cSThomas Graf 
162fceb6435SJohannes Berg int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len,
163fceb6435SJohannes Berg 			struct netlink_ext_ack *exterr);
164e7199288SPavel Emelianov 
16538f7b870SPatrick McHardy #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
16638f7b870SPatrick McHardy 
167e2849863SThomas Graf #endif
168