shill: Elevates raw netlink attributes to fully-fledged attributes.
This CL contains several small modifications to get and set raw
attributes like the other attributes and removes back doors used by
code to parse raw attribute data outside of the NetlinkAttribute
mechanism. As part of this, netlink attribute headers have been removed
from the raw attribute data.
BUG=None.
TEST=unittests
Change-Id: I201ce7ffbc85558ae97a492921c3f5f4bfc4d0d4
Reviewed-on: https://gerrit.chromium.org/gerrit/44185
Commit-Queue: Wade Guthrie <wdg@chromium.org>
Reviewed-by: Wade Guthrie <wdg@chromium.org>
Tested-by: Wade Guthrie <wdg@chromium.org>
diff --git a/attribute_list.cc b/attribute_list.cc
index 6cea9f7..757f150 100644
--- a/attribute_list.cc
+++ b/attribute_list.cc
@@ -277,27 +277,25 @@
return false;
if (output) {
- const nlattr *const_data =
- reinterpret_cast<const nlattr *>(raw_value.GetConstData());
- // nla_data and nla_len don't change their parameters but don't declare
- // them to be const. Hence the cast.
- nlattr *data_nlattr = const_cast<nlattr *>(const_data);
- *output = ByteString(
- reinterpret_cast<unsigned char *>(nla_data(data_nlattr)),
- nla_len(data_nlattr));
+ *output = raw_value;
}
return true;
}
-const NetlinkRawAttribute *AttributeList::GetRawAttribute(
- int id) const {
- if (!HasRawAttribute(id)) {
- LOG(ERROR) << "No attribute " << id << " of type kTypeRaw exists.";
- return NULL;
+bool AttributeList::SetRawAttributeValue(int id, ByteString value) {
+ NetlinkAttribute *attribute = GetAttribute(id);
+ if (!attribute)
+ return false;
+ return attribute->SetRawValue(value);
+}
+
+bool AttributeList::CreateRawAttribute(int id, const char *id_string) {
+ if (ContainsKey(attributes_, id)) {
+ LOG(ERROR) << "Trying to re-add attribute: " << id;
+ return false;
}
- const NetlinkRawAttribute *attr =
- reinterpret_cast<const NetlinkRawAttribute *>(GetAttribute(id));
- return attr;
+ attributes_[id] = AttributePointer(new NetlinkRawAttribute(id, id_string));
+ return true;
}
NetlinkAttribute *AttributeList::GetAttribute(int id) const {
@@ -309,15 +307,4 @@
return i->second.get();
}
-bool AttributeList::HasRawAttribute(int id) const {
- map<int, AttributePointer>::const_iterator i;
- i = attributes_.find(id);
- if (i == attributes_.end()) {
- LOG(ERROR) << "FALSE - Didn't find id " << id;
- return false;
- }
- return (i->second->datatype() == NetlinkAttribute::kTypeRaw) ? true : false;
-}
-
-
} // namespace shill