1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2e2849863SThomas Graf #ifndef __NET_RTNETLINK_H 3e2849863SThomas Graf #define __NET_RTNETLINK_H 4e2849863SThomas Graf 5e2849863SThomas Graf #include <linux/rtnetlink.h> 6e2849863SThomas Graf #include <net/netlink.h> 7e2849863SThomas Graf 8c21ef3e3SDavid Ahern typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *, 9c21ef3e3SDavid Ahern struct netlink_ext_ack *); 10e2849863SThomas Graf typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *); 11e2849863SThomas Graf 1262256f98SFlorian Westphal enum rtnl_link_flags { 1362256f98SFlorian Westphal RTNL_FLAG_DOIT_UNLOCKED = 1, 1462256f98SFlorian Westphal }; 1562256f98SFlorian Westphal 16efb48ccfSJoe Perches int __rtnl_register(int protocol, int msgtype, 17b97bac64SFlorian Westphal rtnl_doit_func, rtnl_dumpit_func, unsigned int flags); 18efb48ccfSJoe Perches void rtnl_register(int protocol, int msgtype, 19b97bac64SFlorian Westphal rtnl_doit_func, rtnl_dumpit_func, unsigned int flags); 20*e4202511SFlorian Westphal int rtnl_register_module(struct module *owner, int protocol, int msgtype, 21*e4202511SFlorian Westphal rtnl_doit_func, rtnl_dumpit_func, unsigned int flags); 22efb48ccfSJoe Perches int rtnl_unregister(int protocol, int msgtype); 23efb48ccfSJoe Perches void rtnl_unregister_all(int protocol); 24e2849863SThomas Graf 253a6c2b41SPatrick McHardy static inline int rtnl_msg_family(const struct nlmsghdr *nlh) 26c454673dSThomas Graf { 27c454673dSThomas Graf if (nlmsg_len(nlh) >= sizeof(struct rtgenmsg)) 28c454673dSThomas Graf return ((struct rtgenmsg *) nlmsg_data(nlh))->rtgen_family; 29c454673dSThomas Graf else 30c454673dSThomas Graf return AF_UNSPEC; 31c454673dSThomas Graf } 32c454673dSThomas Graf 3338f7b870SPatrick McHardy /** 3438f7b870SPatrick McHardy * struct rtnl_link_ops - rtnetlink link operations 3538f7b870SPatrick McHardy * 3638f7b870SPatrick McHardy * @list: Used internally 3738f7b870SPatrick McHardy * @kind: Identifier 3838f7b870SPatrick McHardy * @maxtype: Highest device specific netlink attribute number 3938f7b870SPatrick McHardy * @policy: Netlink policy for device specific attribute validation 4038f7b870SPatrick McHardy * @validate: Optional validation function for netlink/changelink parameters 4138f7b870SPatrick McHardy * @priv_size: sizeof net_device private space 4238f7b870SPatrick McHardy * @setup: net_device setup function 4338f7b870SPatrick McHardy * @newlink: Function for configuring and registering a new device 4438f7b870SPatrick McHardy * @changelink: Function for changing parameters of an existing device 4538f7b870SPatrick McHardy * @dellink: Function to remove a device 4638f7b870SPatrick McHardy * @get_size: Function to calculate required room for dumping device 4738f7b870SPatrick McHardy * specific netlink attributes 4838f7b870SPatrick McHardy * @fill_info: Function to dump device specific netlink attributes 499b17876fSstephen hemminger * @get_xstats_size: Function to calculate required room for dumping device 5038f7b870SPatrick McHardy * specific statistics 5138f7b870SPatrick McHardy * @fill_xstats: Function to dump device specific statistics 52d40156aaSJiri Pirko * @get_num_tx_queues: Function to determine number of transmit queues 53d40156aaSJiri Pirko * to create when creating a new device. 54d40156aaSJiri Pirko * @get_num_rx_queues: Function to determine number of receive queues 55d40156aaSJiri Pirko * to create when creating a new device. 56d37512a2SNicolas Dichtel * @get_link_net: Function to get the i/o netns of the device 5797a47facSNikolay Aleksandrov * @get_linkxstats_size: Function to calculate the required room for 5897a47facSNikolay Aleksandrov * dumping device-specific extended link stats 5997a47facSNikolay Aleksandrov * @fill_linkxstats: Function to dump device-specific extended link stats 6038f7b870SPatrick McHardy */ 6138f7b870SPatrick McHardy struct rtnl_link_ops { 6238f7b870SPatrick McHardy struct list_head list; 6338f7b870SPatrick McHardy 6438f7b870SPatrick McHardy const char *kind; 6538f7b870SPatrick McHardy 6638f7b870SPatrick McHardy size_t priv_size; 6738f7b870SPatrick McHardy void (*setup)(struct net_device *dev); 6838f7b870SPatrick McHardy 6938f7b870SPatrick McHardy int maxtype; 7038f7b870SPatrick McHardy const struct nla_policy *policy; 7138f7b870SPatrick McHardy int (*validate)(struct nlattr *tb[], 72a8b8a889SMatthias Schiffer struct nlattr *data[], 73a8b8a889SMatthias Schiffer struct netlink_ext_ack *extack); 7438f7b870SPatrick McHardy 7581adee47SEric W. Biederman int (*newlink)(struct net *src_net, 7681adee47SEric W. Biederman struct net_device *dev, 7738f7b870SPatrick McHardy struct nlattr *tb[], 787a3f4a18SMatthias Schiffer struct nlattr *data[], 797a3f4a18SMatthias Schiffer struct netlink_ext_ack *extack); 8038f7b870SPatrick McHardy int (*changelink)(struct net_device *dev, 8138f7b870SPatrick McHardy struct nlattr *tb[], 82ad744b22SMatthias Schiffer struct nlattr *data[], 83ad744b22SMatthias Schiffer struct netlink_ext_ack *extack); 8423289a37SEric Dumazet void (*dellink)(struct net_device *dev, 8523289a37SEric Dumazet struct list_head *head); 8638f7b870SPatrick McHardy 8738f7b870SPatrick McHardy size_t (*get_size)(const struct net_device *dev); 8838f7b870SPatrick McHardy int (*fill_info)(struct sk_buff *skb, 8938f7b870SPatrick McHardy const struct net_device *dev); 9038f7b870SPatrick McHardy 9138f7b870SPatrick McHardy size_t (*get_xstats_size)(const struct net_device *dev); 9238f7b870SPatrick McHardy int (*fill_xstats)(struct sk_buff *skb, 9338f7b870SPatrick McHardy const struct net_device *dev); 94d40156aaSJiri Pirko unsigned int (*get_num_tx_queues)(void); 95d40156aaSJiri Pirko unsigned int (*get_num_rx_queues)(void); 96ba7d49b1SJiri Pirko 97ba7d49b1SJiri Pirko int slave_maxtype; 98ba7d49b1SJiri Pirko const struct nla_policy *slave_policy; 99ba7d49b1SJiri Pirko int (*slave_changelink)(struct net_device *dev, 100ba7d49b1SJiri Pirko struct net_device *slave_dev, 101ba7d49b1SJiri Pirko struct nlattr *tb[], 10217dd0ec4SMatthias Schiffer struct nlattr *data[], 10317dd0ec4SMatthias Schiffer struct netlink_ext_ack *extack); 104ba7d49b1SJiri Pirko size_t (*get_slave_size)(const struct net_device *dev, 105ba7d49b1SJiri Pirko const struct net_device *slave_dev); 106ba7d49b1SJiri Pirko int (*fill_slave_info)(struct sk_buff *skb, 107ba7d49b1SJiri Pirko const struct net_device *dev, 108ba7d49b1SJiri Pirko const struct net_device *slave_dev); 109d37512a2SNicolas Dichtel struct net *(*get_link_net)(const struct net_device *dev); 11080e73cc5SNikolay Aleksandrov size_t (*get_linkxstats_size)(const struct net_device *dev, 11180e73cc5SNikolay Aleksandrov int attr); 11297a47facSNikolay Aleksandrov int (*fill_linkxstats)(struct sk_buff *skb, 11397a47facSNikolay Aleksandrov const struct net_device *dev, 11480e73cc5SNikolay Aleksandrov int *prividx, int attr); 11538f7b870SPatrick McHardy }; 11638f7b870SPatrick McHardy 117efb48ccfSJoe Perches int __rtnl_link_register(struct rtnl_link_ops *ops); 118efb48ccfSJoe Perches void __rtnl_link_unregister(struct rtnl_link_ops *ops); 11938f7b870SPatrick McHardy 120efb48ccfSJoe Perches int rtnl_link_register(struct rtnl_link_ops *ops); 121efb48ccfSJoe Perches void rtnl_link_unregister(struct rtnl_link_ops *ops); 12238f7b870SPatrick McHardy 123f8ff182cSThomas Graf /** 124f8ff182cSThomas Graf * struct rtnl_af_ops - rtnetlink address family operations 125f8ff182cSThomas Graf * 126f8ff182cSThomas Graf * @list: Used internally 127f8ff182cSThomas Graf * @family: Address family 128f8ff182cSThomas Graf * @fill_link_af: Function to fill IFLA_AF_SPEC with address family 129f8ff182cSThomas Graf * specific netlink attributes. 130f8ff182cSThomas Graf * @get_link_af_size: Function to calculate size of address family specific 1319b17876fSstephen hemminger * netlink attributes. 132cf7afbfeSThomas Graf * @validate_link_af: Validate a IFLA_AF_SPEC attribute, must check attr 133cf7afbfeSThomas Graf * for invalid configuration settings. 134cf7afbfeSThomas Graf * @set_link_af: Function to parse a IFLA_AF_SPEC attribute and modify 135f8ff182cSThomas Graf * net_device accordingly. 136f8ff182cSThomas Graf */ 137f8ff182cSThomas Graf struct rtnl_af_ops { 138f8ff182cSThomas Graf struct list_head list; 139f8ff182cSThomas Graf int family; 140f8ff182cSThomas Graf 141f8ff182cSThomas Graf int (*fill_link_af)(struct sk_buff *skb, 142d5566fd7SSowmini Varadhan const struct net_device *dev, 143d5566fd7SSowmini Varadhan u32 ext_filter_mask); 144b1974ed0SArad, Ronen size_t (*get_link_af_size)(const struct net_device *dev, 145b1974ed0SArad, Ronen u32 ext_filter_mask); 146f8ff182cSThomas Graf 147cf7afbfeSThomas Graf int (*validate_link_af)(const struct net_device *dev, 148cf7afbfeSThomas Graf const struct nlattr *attr); 149cf7afbfeSThomas Graf int (*set_link_af)(struct net_device *dev, 150f8ff182cSThomas Graf const struct nlattr *attr); 151aefb4d4aSRobert Shearman 152aefb4d4aSRobert Shearman int (*fill_stats_af)(struct sk_buff *skb, 153aefb4d4aSRobert Shearman const struct net_device *dev); 154aefb4d4aSRobert Shearman size_t (*get_stats_af_size)(const struct net_device *dev); 155f8ff182cSThomas Graf }; 156f8ff182cSThomas Graf 1573678a9d8Sstephen hemminger void rtnl_af_register(struct rtnl_af_ops *ops); 158efb48ccfSJoe Perches void rtnl_af_unregister(struct rtnl_af_ops *ops); 159f8ff182cSThomas Graf 160efb48ccfSJoe Perches struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]); 16178ebb0d0SThomas Graf struct net_device *rtnl_create_link(struct net *net, const char *ifname, 1625517750fSTom Gundersen unsigned char name_assign_type, 163efb48ccfSJoe Perches const struct rtnl_link_ops *ops, 164efb48ccfSJoe Perches struct nlattr *tb[]); 165614732eaSThomas Graf int rtnl_delete_link(struct net_device *dev); 166efb48ccfSJoe Perches int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm); 167f8ff182cSThomas Graf 168fceb6435SJohannes Berg int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len, 169fceb6435SJohannes Berg struct netlink_ext_ack *exterr); 170e7199288SPavel Emelianov 17138f7b870SPatrick McHardy #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind) 17238f7b870SPatrick McHardy 173e2849863SThomas Graf #endif 174