diff options
author | Thomas Graf <tgraf@infradead.org> | 2010-11-21 20:31:54 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-11-28 01:56:08 -0500 |
commit | cf7afbfeb8ceb0187348d0a1a0db61305e25f05f (patch) | |
tree | 8b1c07c8ae6a5b3f6f050d3286b53b3d7d72c858 /net/ipv4/devinet.c | |
parent | 89bf67f1f080c947c92f8773482d9e57767ca292 (diff) |
rtnl: make link af-specific updates atomic
As David pointed out correctly, updates to af-specific attributes
are currently not atomic. If multiple changes are requested and
one of them fails, previous updates may have been applied already
leaving the link behind in a undefined state.
This patch splits the function parse_link_af() into two functions
validate_link_af() and set_link_at(). validate_link_af() is placed
to validate_linkmsg() check for errors as early as possible before
any changes to the link have been made. set_link_af() is called to
commit the changes later.
This method is not fail proof, while it is currently sufficient
to make set_link_af() inerrable and thus 100% atomic, the
validation function method will not be able to detect all error
scenarios in the future, there will likely always be errors
depending on states which are f.e. not protected by rtnl_mutex
and thus may change between validation and setting.
Also, instead of silently ignoring unknown address families and
config blocks for address families which did not register a set
function the errors EAFNOSUPPORT respectively EOPNOSUPPORT are
returned to avoid comitting 4 out of 5 update requests without
notifying the user.
Signed-off-by: Thomas Graf <tgraf@infradead.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/devinet.c')
-rw-r--r-- | net/ipv4/devinet.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 71afc26c2df8..d9f71bae45c4 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c | |||
@@ -1289,14 +1289,14 @@ static const struct nla_policy inet_af_policy[IFLA_INET_MAX+1] = { | |||
1289 | [IFLA_INET_CONF] = { .type = NLA_NESTED }, | 1289 | [IFLA_INET_CONF] = { .type = NLA_NESTED }, |
1290 | }; | 1290 | }; |
1291 | 1291 | ||
1292 | static int inet_parse_link_af(struct net_device *dev, const struct nlattr *nla) | 1292 | static int inet_validate_link_af(const struct net_device *dev, |
1293 | const struct nlattr *nla) | ||
1293 | { | 1294 | { |
1294 | struct in_device *in_dev = __in_dev_get_rcu(dev); | ||
1295 | struct nlattr *a, *tb[IFLA_INET_MAX+1]; | 1295 | struct nlattr *a, *tb[IFLA_INET_MAX+1]; |
1296 | int err, rem; | 1296 | int err, rem; |
1297 | 1297 | ||
1298 | if (!in_dev) | 1298 | if (dev && !__in_dev_get_rcu(dev)) |
1299 | return -EOPNOTSUPP; | 1299 | return -EAFNOSUPPORT; |
1300 | 1300 | ||
1301 | err = nla_parse_nested(tb, IFLA_INET_MAX, nla, inet_af_policy); | 1301 | err = nla_parse_nested(tb, IFLA_INET_MAX, nla, inet_af_policy); |
1302 | if (err < 0) | 1302 | if (err < 0) |
@@ -1314,6 +1314,21 @@ static int inet_parse_link_af(struct net_device *dev, const struct nlattr *nla) | |||
1314 | } | 1314 | } |
1315 | } | 1315 | } |
1316 | 1316 | ||
1317 | return 0; | ||
1318 | } | ||
1319 | |||
1320 | static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla) | ||
1321 | { | ||
1322 | struct in_device *in_dev = __in_dev_get_rcu(dev); | ||
1323 | struct nlattr *a, *tb[IFLA_INET_MAX+1]; | ||
1324 | int rem; | ||
1325 | |||
1326 | if (!in_dev) | ||
1327 | return -EAFNOSUPPORT; | ||
1328 | |||
1329 | if (nla_parse_nested(tb, IFLA_INET_MAX, nla, NULL) < 0) | ||
1330 | BUG(); | ||
1331 | |||
1317 | if (tb[IFLA_INET_CONF]) { | 1332 | if (tb[IFLA_INET_CONF]) { |
1318 | nla_for_each_nested(a, tb[IFLA_INET_CONF], rem) | 1333 | nla_for_each_nested(a, tb[IFLA_INET_CONF], rem) |
1319 | ipv4_devconf_set(in_dev, nla_type(a), nla_get_u32(a)); | 1334 | ipv4_devconf_set(in_dev, nla_type(a), nla_get_u32(a)); |
@@ -1689,7 +1704,8 @@ static struct rtnl_af_ops inet_af_ops = { | |||
1689 | .family = AF_INET, | 1704 | .family = AF_INET, |
1690 | .fill_link_af = inet_fill_link_af, | 1705 | .fill_link_af = inet_fill_link_af, |
1691 | .get_link_af_size = inet_get_link_af_size, | 1706 | .get_link_af_size = inet_get_link_af_size, |
1692 | .parse_link_af = inet_parse_link_af, | 1707 | .validate_link_af = inet_validate_link_af, |
1708 | .set_link_af = inet_set_link_af, | ||
1693 | }; | 1709 | }; |
1694 | 1710 | ||
1695 | void __init devinet_init(void) | 1711 | void __init devinet_init(void) |