aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorThomas Graf <tgraf@infradead.org>2010-11-21 20:31:54 -0500
committerDavid S. Miller <davem@davemloft.net>2010-11-28 01:56:08 -0500
commitcf7afbfeb8ceb0187348d0a1a0db61305e25f05f (patch)
tree8b1c07c8ae6a5b3f6f050d3286b53b3d7d72c858 /net/core
parent89bf67f1f080c947c92f8773482d9e57767ca292 (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/core')
-rw-r--r--net/core/rtnetlink.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index bf69e5871b1..750db57f3bb 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1107,6 +1107,28 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
1107 return -EINVAL; 1107 return -EINVAL;
1108 } 1108 }
1109 1109
1110 if (tb[IFLA_AF_SPEC]) {
1111 struct nlattr *af;
1112 int rem, err;
1113
1114 nla_for_each_nested(af, tb[IFLA_AF_SPEC], rem) {
1115 const struct rtnl_af_ops *af_ops;
1116
1117 if (!(af_ops = rtnl_af_lookup(nla_type(af))))
1118 return -EAFNOSUPPORT;
1119
1120 if (!af_ops->set_link_af)
1121 return -EOPNOTSUPP;
1122
1123 if (af_ops->validate_link_af) {
1124 err = af_ops->validate_link_af(dev,
1125 tb[IFLA_AF_SPEC]);
1126 if (err < 0)
1127 return err;
1128 }
1129 }
1130 }
1131
1110 return 0; 1132 return 0;
1111} 1133}
1112 1134
@@ -1356,12 +1378,9 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
1356 const struct rtnl_af_ops *af_ops; 1378 const struct rtnl_af_ops *af_ops;
1357 1379
1358 if (!(af_ops = rtnl_af_lookup(nla_type(af)))) 1380 if (!(af_ops = rtnl_af_lookup(nla_type(af))))
1359 continue; 1381 BUG();
1360
1361 if (!af_ops->parse_link_af)
1362 continue;
1363 1382
1364 err = af_ops->parse_link_af(dev, af); 1383 err = af_ops->set_link_af(dev, af);
1365 if (err < 0) 1384 if (err < 0)
1366 goto errout; 1385 goto errout;
1367 1386