1
2#ifndef __NET_RTNETLINK_H
3#define __NET_RTNETLINK_H
4
5#include <linux/rtnetlink.h>
6#include <net/netlink.h>
7
8typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *,
9 struct netlink_ext_ack *);
10typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
11
12enum rtnl_link_flags {
13 RTNL_FLAG_DOIT_UNLOCKED = 1,
14};
15
16void rtnl_register(int protocol, int msgtype,
17 rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
18int rtnl_register_module(struct module *owner, int protocol, int msgtype,
19 rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
20int rtnl_unregister(int protocol, int msgtype);
21void rtnl_unregister_all(int protocol);
22
23static 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60struct 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 bool netns_refund;
69 unsigned int maxtype;
70 const struct nla_policy *policy;
71 int (*validate)(struct nlattr *tb[],
72 struct nlattr *data[],
73 struct netlink_ext_ack *extack);
74
75 int (*newlink)(struct net *src_net,
76 struct net_device *dev,
77 struct nlattr *tb[],
78 struct nlattr *data[],
79 struct netlink_ext_ack *extack);
80 int (*changelink)(struct net_device *dev,
81 struct nlattr *tb[],
82 struct nlattr *data[],
83 struct netlink_ext_ack *extack);
84 void (*dellink)(struct net_device *dev,
85 struct list_head *head);
86
87 size_t (*get_size)(const struct net_device *dev);
88 int (*fill_info)(struct sk_buff *skb,
89 const struct net_device *dev);
90
91 size_t (*get_xstats_size)(const struct net_device *dev);
92 int (*fill_xstats)(struct sk_buff *skb,
93 const struct net_device *dev);
94 unsigned int (*get_num_tx_queues)(void);
95 unsigned int (*get_num_rx_queues)(void);
96
97 unsigned int slave_maxtype;
98 const struct nla_policy *slave_policy;
99 int (*slave_changelink)(struct net_device *dev,
100 struct net_device *slave_dev,
101 struct nlattr *tb[],
102 struct nlattr *data[],
103 struct netlink_ext_ack *extack);
104 size_t (*get_slave_size)(const struct net_device *dev,
105 const struct net_device *slave_dev);
106 int (*fill_slave_info)(struct sk_buff *skb,
107 const struct net_device *dev,
108 const struct net_device *slave_dev);
109 struct net *(*get_link_net)(const struct net_device *dev);
110 size_t (*get_linkxstats_size)(const struct net_device *dev,
111 int attr);
112 int (*fill_linkxstats)(struct sk_buff *skb,
113 const struct net_device *dev,
114 int *prividx, int attr);
115};
116
117int __rtnl_link_register(struct rtnl_link_ops *ops);
118void __rtnl_link_unregister(struct rtnl_link_ops *ops);
119
120int rtnl_link_register(struct rtnl_link_ops *ops);
121void rtnl_link_unregister(struct rtnl_link_ops *ops);
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137struct rtnl_af_ops {
138 struct list_head list;
139 int family;
140
141 int (*fill_link_af)(struct sk_buff *skb,
142 const struct net_device *dev,
143 u32 ext_filter_mask);
144 size_t (*get_link_af_size)(const struct net_device *dev,
145 u32 ext_filter_mask);
146
147 int (*validate_link_af)(const struct net_device *dev,
148 const struct nlattr *attr);
149 int (*set_link_af)(struct net_device *dev,
150 const struct nlattr *attr,
151 struct netlink_ext_ack *extack);
152 int (*fill_stats_af)(struct sk_buff *skb,
153 const struct net_device *dev);
154 size_t (*get_stats_af_size)(const struct net_device *dev);
155};
156
157void rtnl_af_register(struct rtnl_af_ops *ops);
158void rtnl_af_unregister(struct rtnl_af_ops *ops);
159
160struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
161struct net_device *rtnl_create_link(struct net *net, const char *ifname,
162 unsigned char name_assign_type,
163 const struct rtnl_link_ops *ops,
164 struct nlattr *tb[],
165 struct netlink_ext_ack *extack);
166int rtnl_delete_link(struct net_device *dev);
167int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm);
168
169int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len,
170 struct netlink_ext_ack *exterr);
171struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid);
172
173#define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
174
175#endif
176