rtnetlink: Link address family API
Subsystems (2)
PATCH 1/4 rtnetlink: Link address family API
Each net_device contains address family specific data such as per device settings and statistics. We already expose this data via procfs/sysfs and partially netlink.
The netlink method requires the requester to send one RTM_GETLINK request for each address family it wishes to receive data of and then merge this data itself.
This patch implements a new API which combines all address family specific link data in a new netlink attribute IFLA_AF_SPEC. IFLA_AF_SPEC contains a sequence of nested attributes, one for each address family which in turn defines the structure of its own attribute. Example:
[IFLA_AF_SPEC] = {
[AF_INET] = {
[IFLA_INET_CONF] = ...,
},
[AF_INET6] = {
[IFLA_INET6_FLAGS] = ...,
[IFLA_INET6_CONF] = ...,
}
}The API also allows for address families to implement a function which parses the IFLA_AF_SPEC attribute sent by userspace to implement address family specific link options.
include/linux/if_link.h +19 -0
@@ -80,6 +80,24 @@ struct rtnl_link_ifmap {__u8 port; }; +/* +* IFLA_AF_SPEC +* Contains nested attributes for address family specific attributes. +* Each address family may create a attribute with the address family +* number as type and create its own attribute structure in it. +* +* Example: +* [IFLA_AF_SPEC] = { +* [AF_INET] = { +* [IFLA_INET_CONF] = ..., +* }, +* [AF_INET6] = { +* [IFLA_INET6_FLAGS] = ..., +* [IFLA_INET6_CONF] = ..., +* } +* } +*/ +enum {IFLA_UNSPEC ,IFLA_ADDRESS ,
@@ -116,6 +134,7 @@ enum {IFLA_STATS64 ,IFLA_VF_PORTS ,IFLA_PORT_SELF , +IFLA_AF_SPEC , __IFLA_MAX };
include/net/rtnetlink.h +31 -0
@@ -83,6 +83,37 @@ extern void __rtnl_link_unregister(strucextern int rtnl_link_register (struct rtnl_link_ops *ops);extern void rtnl_link_unregister (struct rtnl_link_ops *ops); +/** +* struct rtnl_af_ops - rtnetlink address family operations +* +* @list: Used internally +* @family: Address family +* @fill_link_af: Function to fill IFLA_AF_SPEC with address family +* specific netlink attributes. +* @get_link_af_size: Function to calculate size of address family specific +* netlink attributes exlusive the container attribute. +* @parse_link_af: Function to parse a IFLA_AF_SPEC attribute and modify +* net_device accordingly. +*/ +struct rtnl_af_ops { +struct list_head list; +int family; + +int (*fill_link_af)(struct sk_buff *skb, +const struct net_device *dev); +size_t (*get_link_af_size)(const struct net_device *dev); + +int (*parse_link_af)(struct net_device *dev, +const struct nlattr *attr); +}; + +extern int __rtnl_af_register (struct rtnl_af_ops *ops); +extern void __rtnl_af_unregister (struct rtnl_af_ops *ops); + +extern int rtnl_af_register (struct rtnl_af_ops *ops); +extern void rtnl_af_unregister (struct rtnl_af_ops *ops); + +extern struct net *rtnl_link_get_net (struct net *src_net,struct nlattr *tb[]);extern struct net_device *rtnl_create_link (struct net *src_net,struct net *net,char *ifname,const struct rtnl_link_ops *ops,struct nlattr *tb[]);
net/core/rtnetlink.c +145 -2
183 lines not on this page · raw message
David Miller
maintainerFrom: Thomas Graf <[email protected]>
Date: Tue, 16 Nov 2010 09:30:14 -0500
Quoted 24 lines
Each
net_devicecontains address family specific data such as per device settings and statistics. We already expose this data via procfs/sysfs and partially netlink.The netlink method requires the requester to send one
RTM_GETLINKrequest for each address family it wishes to receive data of and then merge this data itself.This patch implements a new API which combines all address family specific link data in a new netlink attribute
IFLA_AF_SPEC.IFLA_AF_SPECcontains a sequence of nested attributes, one for each address family which in turn defines the structure of its own attribute. Example:[IFLA_AF_SPEC] = { [AF_INET] = { [IFLA_INET_CONF] = ..., }, [AF_INET6] = { [IFLA_INET6_FLAGS] = ..., [IFLA_INET6_CONF] = ..., } }
Quoted 5 lines
The API also allows for address families to implement a function which parses the
IFLA_AF_SPECattribute sent by userspace to implement address family specific link options.Signed-off-by Thomas Graf <[email protected]>
Applied, but note that as-implemented it has the "partial update" problem. When we can't get the af-specific ops for a "parse" operation, we just skip that AF yet we let the modifications of the other AF's succeed and make it appear to the user that everything got updated and all the attributes were consumed.
I don't know what we can do about this with how things work right now.
Quoted 8 lines · David Miller
Applied, but note that as-implemented it has the "partial update" problem. When we can't get the af-specific ops for a "parse" operation, we just skip that AF yet we let the modifications of the other AF's succeed and make it appear to the user that everything got updated and all the attributes were consumed.
I don't know what we can do about this with how things work right now.
I absolutely agree and this problem isn't limited to this specific case at all. All netlink based implementations I am aware of will silently skip over any unknown attribute type and thus only apply updates partially.
What I can will do in this specific case is check if all af ops can be looked up before starting to update things.
Some of the newer netlink interfaces are actually both atomic and always leave a consistent state. For those which do not I strongly believe that we should limit inconsistency to a minimum were possible but leave any kind of fallback mechanism to userspace. I am experimenting with this in userspace. By listening to notifications and with the help of sequence numbers it is possible to reliably switch back to a previous "version" of a link, address, ... even if there are multiple writers.