0001
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
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
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
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
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