Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __NET_RTNETLINK_H
0003 #define __NET_RTNETLINK_H
0004 
0005 #include <linux/rtnetlink.h>
0006 #include <net/netlink.h>
0007 
0008 typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *,
0009                   struct netlink_ext_ack *);
0010 typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
0011 
0012 enum rtnl_link_flags {
0013     RTNL_FLAG_DOIT_UNLOCKED     = BIT(0),
0014     RTNL_FLAG_BULK_DEL_SUPPORTED    = BIT(1),
0015 };
0016 
0017 enum rtnl_kinds {
0018     RTNL_KIND_NEW,
0019     RTNL_KIND_DEL,
0020     RTNL_KIND_GET,
0021     RTNL_KIND_SET
0022 };
0023 #define RTNL_KIND_MASK 0x3
0024 
0025 static inline enum rtnl_kinds rtnl_msgtype_kind(int msgtype)
0026 {
0027     return msgtype & RTNL_KIND_MASK;
0028 }
0029 
0030 void rtnl_register(int protocol, int msgtype,
0031            rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
0032 int rtnl_register_module(struct module *owner, int protocol, int msgtype,
0033              rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
0034 int rtnl_unregister(int protocol, int msgtype);
0035 void rtnl_unregister_all(int protocol);
0036 
0037 static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
0038 {
0039     if (nlmsg_len(nlh) >= sizeof(struct rtgenmsg))
0040         return ((struct rtgenmsg *) nlmsg_data(nlh))->rtgen_family;
0041     else
0042         return AF_UNSPEC;
0043 }
0044 
0045 /**
0046  *  struct rtnl_link_ops - rtnetlink link operations
0047  *
0048  *  @list: Used internally
0049  *  @kind: Identifier
0050  *  @netns_refund: Physical device, move to init_net on netns exit
0051  *  @maxtype: Highest device specific netlink attribute number
0052  *  @policy: Netlink policy for device specific attribute validation
0053  *  @validate: Optional validation function for netlink/changelink parameters
0054  *  @alloc: netdev allocation function, can be %NULL and is then used
0055  *      in place of alloc_netdev_mqs(), in this case @priv_size
0056  *      and @setup are unused. Returns a netdev or ERR_PTR().
0057  *  @priv_size: sizeof net_device private space
0058  *  @setup: net_device setup function
0059  *  @newlink: Function for configuring and registering a new device
0060  *  @changelink: Function for changing parameters of an existing device
0061  *  @dellink: Function to remove a device
0062  *  @get_size: Function to calculate required room for dumping device
0063  *         specific netlink attributes
0064  *  @fill_info: Function to dump device specific netlink attributes
0065  *  @get_xstats_size: Function to calculate required room for dumping device
0066  *            specific statistics
0067  *  @fill_xstats: Function to dump device specific statistics
0068  *  @get_num_tx_queues: Function to determine number of transmit queues
0069  *              to create when creating a new device.
0070  *  @get_num_rx_queues: Function to determine number of receive queues
0071  *              to create when creating a new device.
0072  *  @get_link_net: Function to get the i/o netns of the device
0073  *  @get_linkxstats_size: Function to calculate the required room for
0074  *                dumping device-specific extended link stats
0075  *  @fill_linkxstats: Function to dump device-specific extended link stats
0076  */
0077 struct rtnl_link_ops {
0078     struct list_head    list;
0079 
0080     const char      *kind;
0081 
0082     size_t          priv_size;
0083     struct net_device   *(*alloc)(struct nlattr *tb[],
0084                       const char *ifname,
0085                       unsigned char name_assign_type,
0086                       unsigned int num_tx_queues,
0087                       unsigned int num_rx_queues);
0088     void            (*setup)(struct net_device *dev);
0089 
0090     bool            netns_refund;
0091     unsigned int        maxtype;
0092     const struct nla_policy *policy;
0093     int         (*validate)(struct nlattr *tb[],
0094                         struct nlattr *data[],
0095                         struct netlink_ext_ack *extack);
0096 
0097     int         (*newlink)(struct net *src_net,
0098                        struct net_device *dev,
0099                        struct nlattr *tb[],
0100                        struct nlattr *data[],
0101                        struct netlink_ext_ack *extack);
0102     int         (*changelink)(struct net_device *dev,
0103                           struct nlattr *tb[],
0104                           struct nlattr *data[],
0105                           struct netlink_ext_ack *extack);
0106     void            (*dellink)(struct net_device *dev,
0107                        struct list_head *head);
0108 
0109     size_t          (*get_size)(const struct net_device *dev);
0110     int         (*fill_info)(struct sk_buff *skb,
0111                          const struct net_device *dev);
0112 
0113     size_t          (*get_xstats_size)(const struct net_device *dev);
0114     int         (*fill_xstats)(struct sk_buff *skb,
0115                            const struct net_device *dev);
0116     unsigned int        (*get_num_tx_queues)(void);
0117     unsigned int        (*get_num_rx_queues)(void);
0118 
0119     unsigned int        slave_maxtype;
0120     const struct nla_policy *slave_policy;
0121     int         (*slave_changelink)(struct net_device *dev,
0122                             struct net_device *slave_dev,
0123                             struct nlattr *tb[],
0124                             struct nlattr *data[],
0125                             struct netlink_ext_ack *extack);
0126     size_t          (*get_slave_size)(const struct net_device *dev,
0127                           const struct net_device *slave_dev);
0128     int         (*fill_slave_info)(struct sk_buff *skb,
0129                            const struct net_device *dev,
0130                            const struct net_device *slave_dev);
0131     struct net      *(*get_link_net)(const struct net_device *dev);
0132     size_t          (*get_linkxstats_size)(const struct net_device *dev,
0133                                int attr);
0134     int         (*fill_linkxstats)(struct sk_buff *skb,
0135                            const struct net_device *dev,
0136                            int *prividx, int attr);
0137 };
0138 
0139 int __rtnl_link_register(struct rtnl_link_ops *ops);
0140 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
0141 
0142 int rtnl_link_register(struct rtnl_link_ops *ops);
0143 void rtnl_link_unregister(struct rtnl_link_ops *ops);
0144 
0145 /**
0146  *  struct rtnl_af_ops - rtnetlink address family operations
0147  *
0148  *  @list: Used internally
0149  *  @family: Address family
0150  *  @fill_link_af: Function to fill IFLA_AF_SPEC with address family
0151  *             specific netlink attributes.
0152  *  @get_link_af_size: Function to calculate size of address family specific
0153  *             netlink attributes.
0154  *  @validate_link_af: Validate a IFLA_AF_SPEC attribute, must check attr
0155  *             for invalid configuration settings.
0156  *  @set_link_af: Function to parse a IFLA_AF_SPEC attribute and modify
0157  *            net_device accordingly.
0158  */
0159 struct rtnl_af_ops {
0160     struct list_head    list;
0161     int         family;
0162 
0163     int         (*fill_link_af)(struct sk_buff *skb,
0164                         const struct net_device *dev,
0165                         u32 ext_filter_mask);
0166     size_t          (*get_link_af_size)(const struct net_device *dev,
0167                             u32 ext_filter_mask);
0168 
0169     int         (*validate_link_af)(const struct net_device *dev,
0170                             const struct nlattr *attr,
0171                             struct netlink_ext_ack *extack);
0172     int         (*set_link_af)(struct net_device *dev,
0173                            const struct nlattr *attr,
0174                            struct netlink_ext_ack *extack);
0175     int         (*fill_stats_af)(struct sk_buff *skb,
0176                          const struct net_device *dev);
0177     size_t          (*get_stats_af_size)(const struct net_device *dev);
0178 };
0179 
0180 void rtnl_af_register(struct rtnl_af_ops *ops);
0181 void rtnl_af_unregister(struct rtnl_af_ops *ops);
0182 
0183 struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
0184 struct net_device *rtnl_create_link(struct net *net, const char *ifname,
0185                     unsigned char name_assign_type,
0186                     const struct rtnl_link_ops *ops,
0187                     struct nlattr *tb[],
0188                     struct netlink_ext_ack *extack);
0189 int rtnl_delete_link(struct net_device *dev);
0190 int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm);
0191 
0192 int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len,
0193             struct netlink_ext_ack *exterr);
0194 struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid);
0195 
0196 #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
0197 
0198 #endif