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