Address comments on aosp/1559686.

Also remove some unnecessary line wrapping.

Test: atest TetheringTests
Change-Id: Ia7638b3198d7811cdbb34e959c50608cf1a656bf
diff --git a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java
index 8c3f565..35de400 100644
--- a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java
+++ b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java
@@ -245,8 +245,7 @@
         }
 
         /** Get downstream4 BPF map. */
-        @Nullable public BpfMap<Tether4Key, Tether4Value>
-                getBpfDownstream4Map() {
+        @Nullable public BpfMap<Tether4Key, Tether4Value> getBpfDownstream4Map() {
             try {
                 return new BpfMap<>(TETHER_DOWNSTREAM4_MAP_PATH,
                     BpfMap.BPF_F_RDWR, Tether4Key.class, Tether4Value.class);
@@ -257,20 +256,18 @@
         }
 
         /** Get upstream4 BPF map. */
-        @Nullable public BpfMap<Tether4Key, Tether4Value>
-                getBpfUpstream4Map() {
+        @Nullable public BpfMap<Tether4Key, Tether4Value> getBpfUpstream4Map() {
             try {
                 return new BpfMap<>(TETHER_UPSTREAM4_MAP_PATH,
                     BpfMap.BPF_F_RDWR, Tether4Key.class, Tether4Value.class);
             } catch (ErrnoException e) {
                 Log.e(TAG, "Cannot create upstream4 map: " + e);
+                return null;
             }
-            return null;
         }
 
         /** Get downstream6 BPF map. */
-        @Nullable public BpfMap<TetherDownstream6Key, Tether6Value>
-                getBpfDownstream6Map() {
+        @Nullable public BpfMap<TetherDownstream6Key, Tether6Value> getBpfDownstream6Map() {
             try {
                 return new BpfMap<>(TETHER_DOWNSTREAM6_FS_PATH,
                     BpfMap.BPF_F_RDWR, TetherDownstream6Key.class, Tether6Value.class);
@@ -958,7 +955,7 @@
     // TODO: add ether ip support.
     private class BpfConntrackEventConsumer implements ConntrackEventConsumer {
         @NonNull
-        private Tether4Key makeTether4Key(
+        private Tether4Key makeTetherUpstream4Key(
                 @NonNull ConntrackEvent e, @NonNull ClientInfo c) {
             return new Tether4Key(c.downstreamIfindex, c.downstreamMac,
                     e.tupleOrig.protoNum, e.tupleOrig.srcIp.getAddress(),
@@ -966,7 +963,7 @@
         }
 
         @NonNull
-        private Tether4Key makeTether4Key(
+        private Tether4Key makeTetherDownstream4Key(
                 @NonNull ConntrackEvent e, @NonNull ClientInfo c, int upstreamIndex) {
             return new Tether4Key(upstreamIndex, NULL_MAC_ADDRESS /* dstMac (rawip) */,
                     e.tupleReply.protoNum, e.tupleReply.srcIp.getAddress(),
@@ -974,7 +971,7 @@
         }
 
         @NonNull
-        private Tether4Value makeTether4Value(@NonNull ConntrackEvent e,
+        private Tether4Value makeTetherUpstream4Value(@NonNull ConntrackEvent e,
                 int upstreamIndex) {
             return new Tether4Value(upstreamIndex,
                     NULL_MAC_ADDRESS /* ethDstMac (rawip) */,
@@ -985,11 +982,12 @@
         }
 
         @NonNull
-        private Tether4Value makeTether4Value(@NonNull ConntrackEvent e,
+        private Tether4Value makeTetherDownstream4Value(@NonNull ConntrackEvent e,
                 @NonNull ClientInfo c, int upstreamIndex) {
             return new Tether4Value(c.downstreamIfindex,
                     c.clientMac, c.downstreamMac, ETH_P_IP, NetworkStackConstants.ETHER_MTU,
-                    e.tupleOrig.dstIp.getAddress(), e.tupleOrig.srcIp.getAddress(),
+                    toIpv4MappedAddressBytes(e.tupleOrig.dstIp),
+                    toIpv4MappedAddressBytes(e.tupleOrig.srcIp),
                     e.tupleOrig.dstPort, e.tupleOrig.srcPort,
                     0 /* lastUsed, filled by bpf prog only */);
         }
@@ -1014,9 +1012,9 @@
             final Integer upstreamIndex = mIpv4UpstreamIndices.get(e.tupleReply.dstIp);
             if (upstreamIndex == null) return;
 
-            final Tether4Key upstream4Key = makeTether4Key(e, tetherClient);
-            final Tether4Key downstream4Key = makeTether4Key(e,
-                    tetherClient, upstreamIndex);
+            final Tether4Key upstream4Key = makeTetherUpstream4Key(e, tetherClient);
+            final Tether4Key downstream4Key = makeTetherDownstream4Key(e, tetherClient,
+                    upstreamIndex);
 
             if (e.msgType == (NetlinkConstants.NFNL_SUBSYS_CTNETLINK << 8
                     | NetlinkConstants.IPCTNL_MSG_CT_DELETE)) {
@@ -1025,10 +1023,9 @@
                 return;
             }
 
-            final Tether4Value upstream4Value = makeTether4Value(e,
+            final Tether4Value upstream4Value = makeTetherUpstream4Value(e, upstreamIndex);
+            final Tether4Value downstream4Value = makeTetherDownstream4Value(e, tetherClient,
                     upstreamIndex);
-            final Tether4Value downstream4Value = makeTether4Value(e,
-                    tetherClient, upstreamIndex);
 
             mBpfCoordinatorShim.tetherOffloadRuleAdd(false, upstream4Key, upstream4Value);
             mBpfCoordinatorShim.tetherOffloadRuleAdd(true, downstream4Key, downstream4Value);
diff --git a/Tethering/tests/unit/src/android/net/ip/IpServerTest.java b/Tethering/tests/unit/src/android/net/ip/IpServerTest.java
index c26458c..16315cf 100644
--- a/Tethering/tests/unit/src/android/net/ip/IpServerTest.java
+++ b/Tethering/tests/unit/src/android/net/ip/IpServerTest.java
@@ -309,26 +309,22 @@
                     }
 
                     @Nullable
-                    public BpfMap<Tether4Key, Tether4Value>
-                            getBpfDownstream4Map() {
+                    public BpfMap<Tether4Key, Tether4Value> getBpfDownstream4Map() {
                         return mBpfDownstream4Map;
                     }
 
                     @Nullable
-                    public BpfMap<Tether4Key, Tether4Value>
-                            getBpfUpstream4Map() {
+                    public BpfMap<Tether4Key, Tether4Value> getBpfUpstream4Map() {
                         return mBpfUpstream4Map;
                     }
 
                     @Nullable
-                    public BpfMap<TetherDownstream6Key, Tether6Value>
-                            getBpfDownstream6Map() {
+                    public BpfMap<TetherDownstream6Key, Tether6Value> getBpfDownstream6Map() {
                         return mBpfDownstream6Map;
                     }
 
                     @Nullable
-                    public BpfMap<TetherUpstream6Key, Tether6Value>
-                            getBpfUpstream6Map() {
+                    public BpfMap<TetherUpstream6Key, Tether6Value> getBpfUpstream6Map() {
                         return mBpfUpstream6Map;
                     }
 
diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java
index 0f9ca3d..1270e50 100644
--- a/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java
+++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java
@@ -206,26 +206,22 @@
                     }
 
                     @Nullable
-                    public BpfMap<Tether4Key, Tether4Value>
-                            getBpfDownstream4Map() {
+                    public BpfMap<Tether4Key, Tether4Value> getBpfDownstream4Map() {
                         return mBpfDownstream4Map;
                     }
 
                     @Nullable
-                    public BpfMap<Tether4Key, Tether4Value>
-                            getBpfUpstream4Map() {
+                    public BpfMap<Tether4Key, Tether4Value> getBpfUpstream4Map() {
                         return mBpfUpstream4Map;
                     }
 
                     @Nullable
-                    public BpfMap<TetherDownstream6Key, Tether6Value>
-                            getBpfDownstream6Map() {
+                    public BpfMap<TetherDownstream6Key, Tether6Value> getBpfDownstream6Map() {
                         return mBpfDownstream6Map;
                     }
 
                     @Nullable
-                    public BpfMap<TetherUpstream6Key, Tether6Value>
-                            getBpfUpstream6Map() {
+                    public BpfMap<TetherUpstream6Key, Tether6Value> getBpfUpstream6Map() {
                         return mBpfUpstream6Map;
                     }