[RN#9] make clatd functions return -errno

For consistent, return -errno but errno on failure.

Changed functions:
- configure_tun_ip
- detect_mtu
- configure_clat_ipv6_address
- configure_packet_socket
- add_anycast_address

Also fix a return errno bug in configure_tun_ip(),
InterfaceController::setMtu has already returned -errno.

Bug: 212345928
Test: atest ClatdControllerTest
Change-Id: I105d5b0c67a881970a6534fb26878f3af8242e08
diff --git a/server/ClatdController.cpp b/server/ClatdController.cpp
index d816bbb..1ab413a 100644
--- a/server/ClatdController.cpp
+++ b/server/ClatdController.cpp
@@ -437,7 +437,7 @@
  *   v4iface - tunnel interface name
  *   v4Str   - tunnel ipv4 address
  *   mtu     - mtu of tun device
- * returns: 0 on success, errno on failure
+ * returns: 0 on success, -errno on failure
  */
 int ClatdController::configure_tun_ip(const char* v4iface, const char* v4Str, int mtu) {
     ALOGI("Using IPv4 address %s on %s", v4Str, v4iface);
@@ -446,7 +446,7 @@
     // framework will be notified and will assume the interface's configuration has been finalized.
     std::string mtuStr = std::to_string(mtu);
     if (int res = InterfaceController::setMtu(v4iface, mtuStr.c_str())) {
-        ALOGE("setMtu %s failed (%s)", v4iface, strerror(res));
+        ALOGE("setMtu %s failed (%s)", v4iface, strerror(-res));
         return res;
     }
 
@@ -458,7 +458,7 @@
     ifConfig.flags = std::vector<std::string>{std::string(String8(INetd::IF_STATE_UP().string()))};
     const auto& status = InterfaceController::setCfg(ifConfig);
     if (!status.ok()) {
-        ALOGE("configure_tun_ip/setCfg failed: %s", strerror(-status.code()));
+        ALOGE("configure_tun_ip/setCfg failed: %s", strerror(status.code()));
         return -status.code();
     }
 
@@ -470,7 +470,7 @@
  *   sock      - the socket to add the address to
  *   addr      - the IP address to add
  *   ifindex   - index of interface to add the address to
- * returns: 0 on success, errno on failure
+ * returns: 0 on success, -errno on failure
  */
 int ClatdController::add_anycast_address(int sock, struct in6_addr* addr, int ifindex) {
     struct ipv6_mreq mreq = {*addr, ifindex};
@@ -478,7 +478,7 @@
     if (ret) {
         ret = errno;
         ALOGE("setsockopt(IPV6_JOIN_ANYCAST): %s", strerror(errno));
-        return ret;
+        return -ret;
     }
 
     return 0;
@@ -489,7 +489,7 @@
  *   sock    - the socket to configure
  *   addr    - the IP address to filter
  *   ifindex - index of interface to add the filter to
- * returns: 0 on success, errno on failure
+ * returns: 0 on success, -errno on failure
  */
 int ClatdController::configure_packet_socket(int sock, in6_addr* addr, int ifindex) {
     uint32_t* ipv6 = addr->s6_addr32;
@@ -518,7 +518,7 @@
     if (setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter))) {
         int res = errno;
         ALOGE("attach packet filter failed: %s", strerror(errno));
-        return res;
+        return -res;
     }
 
     struct sockaddr_ll sll = {
@@ -531,7 +531,7 @@
     if (bind(sock, (struct sockaddr*)&sll, sizeof(sll))) {
         int res = errno;
         ALOGE("binding packet socket: %s", strerror(errno));
-        return res;
+        return -res;
     }
 
     return 0;
@@ -541,14 +541,14 @@
  * picks the clat IPv6 address and configures packet translation to use it.
  *   tunnel - tun device data
  *   interface - uplink interface name
- * returns: 0 on success, errno on failure
+ * returns: 0 on success, -errno on failure
  */
 int ClatdController::configure_clat_ipv6_address(struct ClatdTracker* tracker,
                                                  struct tun_data* tunnel) {
     ALOGI("Using IPv6 address %s on %s", tracker->v6Str, tracker->iface);
 
     // Start translating packets to the new prefix.
-    // TODO: return if error?
+    // TODO: return if error. b/212679140 needs to be fixed first.
     add_anycast_address(tunnel->write_fd6, &tracker->v6, tracker->ifIndex);
 
     // Update our packet socket filter to reflect the new 464xlat IP address.
@@ -613,7 +613,7 @@
  * reads the configuration and applies it to the interface
  *   tracker - clat tracker
  *   tunnel - tun device data
- * returns: 0 on success, errno on failure
+ * returns: 0 on success, -errno on failure
  */
 int ClatdController::configure_interface(struct ClatdTracker* tracker, struct tun_data* tunnel) {
     int res = detect_mtu(&tracker->pfx96, htonl(0x08080808), tracker->fwmark.intValue);