diff options
author | Vinit Deshpande <vinitd@google.com> | 2015-03-15 13:40:20 -0700 |
---|---|---|
committer | Vinit Deshpande <vinitd@google.com> | 2015-03-15 13:40:20 -0700 |
commit | f5fabf1542624005a0e978045bdd117a62ab2593 (patch) | |
tree | 5980d89720ad276c8c92780419e324c671038768 | |
parent | f66b06886b8c9a08423c11698a3cb61f0de066f8 (diff) | |
parent | 35e36db1d726f5741e7d8d83d2556e1417642be9 (diff) | |
download | frameworks_base-f5fabf1542624005a0e978045bdd117a62ab2593.zip frameworks_base-f5fabf1542624005a0e978045bdd117a62ab2593.tar.gz frameworks_base-f5fabf1542624005a0e978045bdd117a62ab2593.tar.bz2 |
am "Separate NAT from forwarding."
merged from goog/mirror-m-wireless-internal-release
35e36db Separate NAT from forwarding.
3 files changed, 44 insertions, 0 deletions
diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl index f0660eb..f93550a 100644 --- a/core/java/android/os/INetworkManagementService.aidl +++ b/core/java/android/os/INetworkManagementService.aidl @@ -178,6 +178,18 @@ interface INetworkManagementService String[] getDnsForwarders(); /** + * Enables unidirectional packet forwarding from {@code fromIface} to + * {@code toIface}. + */ + void startInterfaceForwarding(String fromIface, String toIface); + + /** + * Disables unidirectional packet forwarding from {@code fromIface} to + * {@code toIface}. + */ + void stopInterfaceForwarding(String fromIface, String toIface); + + /** * Enables Network Address Translation between two interfaces. * The address and netmask of the external interface is used for * the NAT'ed network. diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java index 8f14b12..7b542be 100644 --- a/services/core/java/com/android/server/NetworkManagementService.java +++ b/services/core/java/com/android/server/NetworkManagementService.java @@ -1293,6 +1293,27 @@ public class NetworkManagementService extends INetworkManagementService.Stub return filtered; } + private void modifyInterfaceForward(boolean add, String fromIface, String toIface) { + final Command cmd = new Command("ipfwd", add ? "add" : "remove", fromIface, toIface); + try { + mConnector.execute(cmd); + } catch (NativeDaemonConnectorException e) { + throw e.rethrowAsParcelableException(); + } + } + + @Override + public void startInterfaceForwarding(String fromIface, String toIface) { + mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); + modifyInterfaceForward(true, fromIface, toIface); + } + + @Override + public void stopInterfaceForwarding(String fromIface, String toIface) { + mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); + modifyInterfaceForward(false, fromIface, toIface); + } + private void modifyNat(String action, String internalInterface, String externalInterface) throws SocketException { final Command cmd = new Command("nat", action, internalInterface, externalInterface); diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java index 253c196..f9b6270 100644 --- a/services/core/java/com/android/server/connectivity/Tethering.java +++ b/services/core/java/com/android/server/connectivity/Tethering.java @@ -979,6 +979,12 @@ public class Tethering extends BaseNetworkObserver { if (VDBG) Log.e(TAG, "Exception in forceUpdate: " + e.toString()); } try { + mNMService.stopInterfaceForwarding(mIfaceName, mMyUpstreamIfaceName); + } catch (Exception e) { + if (VDBG) Log.e( + TAG, "Exception in removeInterfaceForward: " + e.toString()); + } + try { mNMService.disableNat(mIfaceName, mMyUpstreamIfaceName); } catch (Exception e) { if (VDBG) Log.e(TAG, "Exception in disableNat: " + e.toString()); @@ -1031,9 +1037,14 @@ public class Tethering extends BaseNetworkObserver { if (newUpstreamIfaceName != null) { try { mNMService.enableNat(mIfaceName, newUpstreamIfaceName); + mNMService.startInterfaceForwarding(mIfaceName, + newUpstreamIfaceName); } catch (Exception e) { Log.e(TAG, "Exception enabling Nat: " + e.toString()); try { + mNMService.disableNat(mIfaceName, newUpstreamIfaceName); + } catch (Exception ee) {} + try { mNMService.untetherInterface(mIfaceName); } catch (Exception ee) {} |