patchpanel: Account for long ifnames

This patch modifies the veth ifname naming function for ARC
container to account for longer device names that, when prefixed, exceed
IFNAMSIZ.

The 'veth' prefix itself must still be used since that's what shill is
paying attention to.

BUG=b:155453410
TEST=units, manual inspection and connectivity check

Change-Id: I3e0abcced0d8a6df1782093e682212a7ce2ae078
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2192631
Tested-by: Garrick Evans <garrick@chromium.org>
Commit-Queue: Garrick Evans <garrick@chromium.org>
Reviewed-by: Taoyu Li <taoyl@chromium.org>
Reviewed-by: Hugo Benichi <hugobenichi@google.com>
diff --git a/patchpanel/datapath.cc b/patchpanel/datapath.cc
index 7670730..3f2c5f4 100644
--- a/patchpanel/datapath.cc
+++ b/patchpanel/datapath.cc
@@ -34,12 +34,17 @@
 
 }  // namespace
 
-std::string ArcVethHostName(std::string ifname) {
-  return "veth_" + ifname;
-}
+std::string ArcVethHostName(const std::string& ifname) {
+  std::string n = "veth" + ifname;
+  if (n.length() < IFNAMSIZ)
+    return n;
 
-std::string ArcVethPeerName(std::string ifname) {
-  return "peer_" + ifname;
+  // Best effort attempt to preserve the interface number, assuming it's the
+  // last char in the name.
+  auto c = ifname[ifname.length() - 1];
+  n.resize(IFNAMSIZ - 1);
+  n[n.length() - 1] = c;
+  return n;
 }
 
 Datapath::Datapath(MinijailedProcessRunner* process_runner)