GNU Linux-libre 4.14.294-gnu1
[releases.git] / include / net / rtnetlink.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NET_RTNETLINK_H
3 #define __NET_RTNETLINK_H
4
5 #include <linux/rtnetlink.h>
6 #include <net/netlink.h>
7
8 typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *,
9                               struct netlink_ext_ack *);
10 typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
11
12 enum rtnl_link_flags {
13         RTNL_FLAG_DOIT_UNLOCKED = 1,
14 };
15
16 int __rtnl_register(int protocol, int msgtype,
17                     rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
18 void rtnl_register(int protocol, int msgtype,
19                    rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
20 int rtnl_unregister(int protocol, int msgtype);
21 void rtnl_unregister_all(int protocol);
22
23 static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
24 {
25         if (nlmsg_len(nlh) >= sizeof(struct rtgenmsg))
26                 return ((struct rtgenmsg *) nlmsg_data(nlh))->rtgen_family;
27         else
28                 return AF_UNSPEC;
29 }
30
31 /**
32  *      struct rtnl_link_ops - rtnetlink link operations
33  *
34  *      @list: Used internally
35  *      @kind: Identifier
36  *      @netns_refund: Physical device, move to init_net on netns exit
37  *      @maxtype: Highest device specific netlink attribute number
38  *      @policy: Netlink policy for device specific attribute validation
39  *      @validate: Optional validation function for netlink/changelink parameters
40  *      @priv_size: sizeof net_device private space
41  *      @setup: net_device setup function
42  *      @newlink: Function for configuring and registering a new device
43  *      @changelink: Function for changing parameters of an existing device
44  *      @dellink: Function to remove a device
45  *      @get_size: Function to calculate required room for dumping device
46  *                 specific netlink attributes
47  *      @fill_info: Function to dump device specific netlink attributes
48  *      @get_xstats_size: Function to calculate required room for dumping device
49  *                        specific statistics
50  *      @fill_xstats: Function to dump device specific statistics
51  *      @get_num_tx_queues: Function to determine number of transmit queues
52  *                          to create when creating a new device.
53  *      @get_num_rx_queues: Function to determine number of receive queues
54  *                          to create when creating a new device.
55  *      @get_link_net: Function to get the i/o netns of the device
56  *      @get_linkxstats_size: Function to calculate the required room for
57  *                            dumping device-specific extended link stats
58  *      @fill_linkxstats: Function to dump device-specific extended link stats
59  */
60 struct rtnl_link_ops {
61         struct list_head        list;
62
63         const char              *kind;
64
65         size_t                  priv_size;
66         void                    (*setup)(struct net_device *dev);
67
68         int                     maxtype;
69         const struct nla_policy *policy;
70         int                     (*validate)(struct nlattr *tb[],
71                                             struct nlattr *data[],
72                                             struct netlink_ext_ack *extack);
73
74         int                     (*newlink)(struct net *src_net,
75                                            struct net_device *dev,
76                                            struct nlattr *tb[],
77                                            struct nlattr *data[],
78                                            struct netlink_ext_ack *extack);
79         int                     (*changelink)(struct net_device *dev,
80                                               struct nlattr *tb[],
81                                               struct nlattr *data[],
82                                               struct netlink_ext_ack *extack);
83         void                    (*dellink)(struct net_device *dev,
84                                            struct list_head *head);
85
86         size_t                  (*get_size)(const struct net_device *dev);
87         int                     (*fill_info)(struct sk_buff *skb,
88                                              const struct net_device *dev);
89
90         size_t                  (*get_xstats_size)(const struct net_device *dev);
91         int                     (*fill_xstats)(struct sk_buff *skb,
92                                                const struct net_device *dev);
93         unsigned int            (*get_num_tx_queues)(void);
94         unsigned int            (*get_num_rx_queues)(void);
95
96         bool                    netns_refund;
97         int                     slave_maxtype;
98         const struct nla_policy *slave_policy;
99         int                     (*slave_validate)(struct nlattr *tb[],
100                                                   struct nlattr *data[],
101                                                   struct netlink_ext_ack *extack);
102         int                     (*slave_changelink)(struct net_device *dev,
103                                                     struct net_device *slave_dev,
104                                                     struct nlattr *tb[],
105                                                     struct nlattr *data[],
106                                                     struct netlink_ext_ack *extack);
107         size_t                  (*get_slave_size)(const struct net_device *dev,
108                                                   const struct net_device *slave_dev);
109         int                     (*fill_slave_info)(struct sk_buff *skb,
110                                                    const struct net_device *dev,
111                                                    const struct net_device *slave_dev);
112         struct net              *(*get_link_net)(const struct net_device *dev);
113         size_t                  (*get_linkxstats_size)(const struct net_device *dev,
114                                                        int attr);
115         int                     (*fill_linkxstats)(struct sk_buff *skb,
116                                                    const struct net_device *dev,
117                                                    int *prividx, int attr);
118 };
119
120 int __rtnl_link_register(struct rtnl_link_ops *ops);
121 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
122
123 int rtnl_link_register(struct rtnl_link_ops *ops);
124 void rtnl_link_unregister(struct rtnl_link_ops *ops);
125
126 /**
127  *      struct rtnl_af_ops - rtnetlink address family operations
128  *
129  *      @list: Used internally
130  *      @family: Address family
131  *      @fill_link_af: Function to fill IFLA_AF_SPEC with address family
132  *                     specific netlink attributes.
133  *      @get_link_af_size: Function to calculate size of address family specific
134  *                         netlink attributes.
135  *      @validate_link_af: Validate a IFLA_AF_SPEC attribute, must check attr
136  *                         for invalid configuration settings.
137  *      @set_link_af: Function to parse a IFLA_AF_SPEC attribute and modify
138  *                    net_device accordingly.
139  */
140 struct rtnl_af_ops {
141         struct list_head        list;
142         int                     family;
143
144         int                     (*fill_link_af)(struct sk_buff *skb,
145                                                 const struct net_device *dev,
146                                                 u32 ext_filter_mask);
147         size_t                  (*get_link_af_size)(const struct net_device *dev,
148                                                     u32 ext_filter_mask);
149
150         int                     (*validate_link_af)(const struct net_device *dev,
151                                                     const struct nlattr *attr);
152         int                     (*set_link_af)(struct net_device *dev,
153                                                const struct nlattr *attr);
154
155         int                     (*fill_stats_af)(struct sk_buff *skb,
156                                                  const struct net_device *dev);
157         size_t                  (*get_stats_af_size)(const struct net_device *dev);
158 };
159
160 void __rtnl_af_unregister(struct rtnl_af_ops *ops);
161
162 void rtnl_af_register(struct rtnl_af_ops *ops);
163 void rtnl_af_unregister(struct rtnl_af_ops *ops);
164
165 struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
166 struct net_device *rtnl_create_link(struct net *net, const char *ifname,
167                                     unsigned char name_assign_type,
168                                     const struct rtnl_link_ops *ops,
169                                     struct nlattr *tb[]);
170 int rtnl_delete_link(struct net_device *dev);
171 int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm);
172
173 int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len,
174                         struct netlink_ext_ack *exterr);
175
176 #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
177
178 #endif