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 16*12dc5c2cSNikolay Aleksandrov enum rtnl_kinds { 17*12dc5c2cSNikolay Aleksandrov RTNL_KIND_NEW, 18*12dc5c2cSNikolay Aleksandrov RTNL_KIND_DEL, 19*12dc5c2cSNikolay Aleksandrov RTNL_KIND_GET, 20*12dc5c2cSNikolay Aleksandrov RTNL_KIND_SET 21*12dc5c2cSNikolay Aleksandrov }; 22*12dc5c2cSNikolay Aleksandrov 23efb48ccfSJoe Perches void rtnl_register(int protocol, int msgtype, 24b97bac64SFlorian Westphal rtnl_doit_func, rtnl_dumpit_func, unsigned int flags); 25e4202511SFlorian Westphal int rtnl_register_module(struct module *owner, int protocol, int msgtype, 26e4202511SFlorian Westphal rtnl_doit_func, rtnl_dumpit_func, unsigned int flags); 27efb48ccfSJoe Perches int rtnl_unregister(int protocol, int msgtype); 28efb48ccfSJoe Perches void rtnl_unregister_all(int protocol); 29e2849863SThomas Graf 303a6c2b41SPatrick McHardy static inline int rtnl_msg_family(const struct nlmsghdr *nlh) 31c454673dSThomas Graf { 32c454673dSThomas Graf if (nlmsg_len(nlh) >= sizeof(struct rtgenmsg)) 33c454673dSThomas Graf return ((struct rtgenmsg *) nlmsg_data(nlh))->rtgen_family; 34c454673dSThomas Graf else 35c454673dSThomas Graf return AF_UNSPEC; 36c454673dSThomas Graf } 37c454673dSThomas Graf 3838f7b870SPatrick McHardy /** 3938f7b870SPatrick McHardy * struct rtnl_link_ops - rtnetlink link operations 4038f7b870SPatrick McHardy * 4138f7b870SPatrick McHardy * @list: Used internally 4238f7b870SPatrick McHardy * @kind: Identifier 433a5ca857SMartin Willi * @netns_refund: Physical device, move to init_net on netns exit 4438f7b870SPatrick McHardy * @maxtype: Highest device specific netlink attribute number 4538f7b870SPatrick McHardy * @policy: Netlink policy for device specific attribute validation 4638f7b870SPatrick McHardy * @validate: Optional validation function for netlink/changelink parameters 478c713dc9SJohannes Berg * @alloc: netdev allocation function, can be %NULL and is then used 488c713dc9SJohannes Berg * in place of alloc_netdev_mqs(), in this case @priv_size 498c713dc9SJohannes Berg * and @setup are unused. Returns a netdev or ERR_PTR(). 5038f7b870SPatrick McHardy * @priv_size: sizeof net_device private space 5138f7b870SPatrick McHardy * @setup: net_device setup function 5238f7b870SPatrick McHardy * @newlink: Function for configuring and registering a new device 5338f7b870SPatrick McHardy * @changelink: Function for changing parameters of an existing device 5438f7b870SPatrick McHardy * @dellink: Function to remove a device 5538f7b870SPatrick McHardy * @get_size: Function to calculate required room for dumping device 5638f7b870SPatrick McHardy * specific netlink attributes 5738f7b870SPatrick McHardy * @fill_info: Function to dump device specific netlink attributes 589b17876fSstephen hemminger * @get_xstats_size: Function to calculate required room for dumping device 5938f7b870SPatrick McHardy * specific statistics 6038f7b870SPatrick McHardy * @fill_xstats: Function to dump device specific statistics 61d40156aaSJiri Pirko * @get_num_tx_queues: Function to determine number of transmit queues 62d40156aaSJiri Pirko * to create when creating a new device. 63d40156aaSJiri Pirko * @get_num_rx_queues: Function to determine number of receive queues 64d40156aaSJiri Pirko * to create when creating a new device. 65d37512a2SNicolas Dichtel * @get_link_net: Function to get the i/o netns of the device 6697a47facSNikolay Aleksandrov * @get_linkxstats_size: Function to calculate the required room for 6797a47facSNikolay Aleksandrov * dumping device-specific extended link stats 6897a47facSNikolay Aleksandrov * @fill_linkxstats: Function to dump device-specific extended link stats 6938f7b870SPatrick McHardy */ 7038f7b870SPatrick McHardy struct rtnl_link_ops { 7138f7b870SPatrick McHardy struct list_head list; 7238f7b870SPatrick McHardy 7338f7b870SPatrick McHardy const char *kind; 7438f7b870SPatrick McHardy 7538f7b870SPatrick McHardy size_t priv_size; 768c713dc9SJohannes Berg struct net_device *(*alloc)(struct nlattr *tb[], 778c713dc9SJohannes Berg const char *ifname, 788c713dc9SJohannes Berg unsigned char name_assign_type, 798c713dc9SJohannes Berg unsigned int num_tx_queues, 808c713dc9SJohannes Berg unsigned int num_rx_queues); 8138f7b870SPatrick McHardy void (*setup)(struct net_device *dev); 8238f7b870SPatrick McHardy 833a5ca857SMartin Willi bool netns_refund; 84ccf8dbcdSKees Cook unsigned int maxtype; 8538f7b870SPatrick McHardy const struct nla_policy *policy; 8638f7b870SPatrick McHardy int (*validate)(struct nlattr *tb[], 87a8b8a889SMatthias Schiffer struct nlattr *data[], 88a8b8a889SMatthias Schiffer struct netlink_ext_ack *extack); 8938f7b870SPatrick McHardy 9081adee47SEric W. Biederman int (*newlink)(struct net *src_net, 9181adee47SEric W. Biederman struct net_device *dev, 9238f7b870SPatrick McHardy struct nlattr *tb[], 937a3f4a18SMatthias Schiffer struct nlattr *data[], 947a3f4a18SMatthias Schiffer struct netlink_ext_ack *extack); 9538f7b870SPatrick McHardy int (*changelink)(struct net_device *dev, 9638f7b870SPatrick McHardy struct nlattr *tb[], 97ad744b22SMatthias Schiffer struct nlattr *data[], 98ad744b22SMatthias Schiffer struct netlink_ext_ack *extack); 9923289a37SEric Dumazet void (*dellink)(struct net_device *dev, 10023289a37SEric Dumazet struct list_head *head); 10138f7b870SPatrick McHardy 10238f7b870SPatrick McHardy size_t (*get_size)(const struct net_device *dev); 10338f7b870SPatrick McHardy int (*fill_info)(struct sk_buff *skb, 10438f7b870SPatrick McHardy const struct net_device *dev); 10538f7b870SPatrick McHardy 10638f7b870SPatrick McHardy size_t (*get_xstats_size)(const struct net_device *dev); 10738f7b870SPatrick McHardy int (*fill_xstats)(struct sk_buff *skb, 10838f7b870SPatrick McHardy const struct net_device *dev); 109d40156aaSJiri Pirko unsigned int (*get_num_tx_queues)(void); 110d40156aaSJiri Pirko unsigned int (*get_num_rx_queues)(void); 111ba7d49b1SJiri Pirko 112ccf8dbcdSKees Cook unsigned int slave_maxtype; 113ba7d49b1SJiri Pirko const struct nla_policy *slave_policy; 114ba7d49b1SJiri Pirko int (*slave_changelink)(struct net_device *dev, 115ba7d49b1SJiri Pirko struct net_device *slave_dev, 116ba7d49b1SJiri Pirko struct nlattr *tb[], 11717dd0ec4SMatthias Schiffer struct nlattr *data[], 11817dd0ec4SMatthias Schiffer struct netlink_ext_ack *extack); 119ba7d49b1SJiri Pirko size_t (*get_slave_size)(const struct net_device *dev, 120ba7d49b1SJiri Pirko const struct net_device *slave_dev); 121ba7d49b1SJiri Pirko int (*fill_slave_info)(struct sk_buff *skb, 122ba7d49b1SJiri Pirko const struct net_device *dev, 123ba7d49b1SJiri Pirko const struct net_device *slave_dev); 124d37512a2SNicolas Dichtel struct net *(*get_link_net)(const struct net_device *dev); 12580e73cc5SNikolay Aleksandrov size_t (*get_linkxstats_size)(const struct net_device *dev, 12680e73cc5SNikolay Aleksandrov int attr); 12797a47facSNikolay Aleksandrov int (*fill_linkxstats)(struct sk_buff *skb, 12897a47facSNikolay Aleksandrov const struct net_device *dev, 12980e73cc5SNikolay Aleksandrov int *prividx, int attr); 13038f7b870SPatrick McHardy }; 13138f7b870SPatrick McHardy 132efb48ccfSJoe Perches int __rtnl_link_register(struct rtnl_link_ops *ops); 133efb48ccfSJoe Perches void __rtnl_link_unregister(struct rtnl_link_ops *ops); 13438f7b870SPatrick McHardy 135efb48ccfSJoe Perches int rtnl_link_register(struct rtnl_link_ops *ops); 136efb48ccfSJoe Perches void rtnl_link_unregister(struct rtnl_link_ops *ops); 13738f7b870SPatrick McHardy 138f8ff182cSThomas Graf /** 139f8ff182cSThomas Graf * struct rtnl_af_ops - rtnetlink address family operations 140f8ff182cSThomas Graf * 141f8ff182cSThomas Graf * @list: Used internally 142f8ff182cSThomas Graf * @family: Address family 143f8ff182cSThomas Graf * @fill_link_af: Function to fill IFLA_AF_SPEC with address family 144f8ff182cSThomas Graf * specific netlink attributes. 145f8ff182cSThomas Graf * @get_link_af_size: Function to calculate size of address family specific 1469b17876fSstephen hemminger * netlink attributes. 147cf7afbfeSThomas Graf * @validate_link_af: Validate a IFLA_AF_SPEC attribute, must check attr 148cf7afbfeSThomas Graf * for invalid configuration settings. 149cf7afbfeSThomas Graf * @set_link_af: Function to parse a IFLA_AF_SPEC attribute and modify 150f8ff182cSThomas Graf * net_device accordingly. 151f8ff182cSThomas Graf */ 152f8ff182cSThomas Graf struct rtnl_af_ops { 153f8ff182cSThomas Graf struct list_head list; 154f8ff182cSThomas Graf int family; 155f8ff182cSThomas Graf 156f8ff182cSThomas Graf int (*fill_link_af)(struct sk_buff *skb, 157d5566fd7SSowmini Varadhan const struct net_device *dev, 158d5566fd7SSowmini Varadhan u32 ext_filter_mask); 159b1974ed0SArad, Ronen size_t (*get_link_af_size)(const struct net_device *dev, 160b1974ed0SArad, Ronen u32 ext_filter_mask); 161f8ff182cSThomas Graf 162cf7afbfeSThomas Graf int (*validate_link_af)(const struct net_device *dev, 1638679c31eSRocco Yue const struct nlattr *attr, 1648679c31eSRocco Yue struct netlink_ext_ack *extack); 165cf7afbfeSThomas Graf int (*set_link_af)(struct net_device *dev, 1663583a4e8SStephen Hemminger const struct nlattr *attr, 1673583a4e8SStephen Hemminger struct netlink_ext_ack *extack); 168aefb4d4aSRobert Shearman int (*fill_stats_af)(struct sk_buff *skb, 169aefb4d4aSRobert Shearman const struct net_device *dev); 170aefb4d4aSRobert Shearman size_t (*get_stats_af_size)(const struct net_device *dev); 171f8ff182cSThomas Graf }; 172f8ff182cSThomas Graf 1733678a9d8Sstephen hemminger void rtnl_af_register(struct rtnl_af_ops *ops); 174efb48ccfSJoe Perches void rtnl_af_unregister(struct rtnl_af_ops *ops); 175f8ff182cSThomas Graf 176efb48ccfSJoe Perches struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]); 17778ebb0d0SThomas Graf struct net_device *rtnl_create_link(struct net *net, const char *ifname, 1785517750fSTom Gundersen unsigned char name_assign_type, 179efb48ccfSJoe Perches const struct rtnl_link_ops *ops, 180d0522f1cSDavid Ahern struct nlattr *tb[], 181d0522f1cSDavid Ahern struct netlink_ext_ack *extack); 182614732eaSThomas Graf int rtnl_delete_link(struct net_device *dev); 183efb48ccfSJoe Perches int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm); 184f8ff182cSThomas Graf 185fceb6435SJohannes Berg int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len, 186fceb6435SJohannes Berg struct netlink_ext_ack *exterr); 187c383edc4SChristian Brauner struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid); 188e7199288SPavel Emelianov 18938f7b870SPatrick McHardy #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind) 19038f7b870SPatrick McHardy 191e2849863SThomas Graf #endif 192