Skip to content
Snippets Groups Projects
Commit 911a7267 authored by Maciej Żenczykowski's avatar Maciej Żenczykowski
Browse files

merge Tether{Down,Up}stream4{Key,Value} - part 3 - fixups


Test: atest, TreeHugger
Signed-off-by: default avatarMaciej Żenczykowski <maze@google.com>
Change-Id: Ia7840698e80ded33d8e0b59efe1ca7267254b892
parent 32874eb6
No related branches found
No related tags found
No related merge requests found
...@@ -134,27 +134,14 @@ public class BpfCoordinatorShimImpl ...@@ -134,27 +134,14 @@ public class BpfCoordinatorShimImpl
} }
@Override @Override
public boolean tetherOffloadRuleAdd(@NonNull Tether4Key key, public boolean tetherOffloadRuleAdd(boolean downstream, @NonNull Tether4Key key,
@NonNull Tether4Value value) { @NonNull Tether4Value value) {
/* no op */ /* no op */
return true; return true;
} }
@Override @Override
public boolean tetherOffloadRuleRemove(@NonNull Tether4Key key) { public boolean tetherOffloadRuleRemove(boolean downstream, @NonNull Tether4Key key) {
/* no op */
return true;
}
@Override
public boolean tetherOffloadRuleAdd(@NonNull Tether4Key key,
@NonNull Tether4Value value) {
/* no op */
return true;
}
@Override
public boolean tetherOffloadRuleRemove(@NonNull Tether4Key key) {
/* no op */ /* no op */
return true; return true;
} }
......
...@@ -248,7 +248,7 @@ public class BpfCoordinatorShimImpl ...@@ -248,7 +248,7 @@ public class BpfCoordinatorShimImpl
} }
@Override @Override
public boolean tetherOffloadRuleAdd(@NonNull Tether4Key key, public boolean tetherOffloadRuleAdd(boolean downstream, @NonNull Tether4Key key,
@NonNull Tether4Value value) { @NonNull Tether4Value value) {
if (!isInitialized()) return false; if (!isInitialized()) return false;
...@@ -257,41 +257,11 @@ public class BpfCoordinatorShimImpl ...@@ -257,41 +257,11 @@ public class BpfCoordinatorShimImpl
// map pair twice causes the unexpected refresh. Must be fixed before starting the // map pair twice causes the unexpected refresh. Must be fixed before starting the
// conntrack timeout extension implementation. // conntrack timeout extension implementation.
// TODO: consider using insertEntry. // TODO: consider using insertEntry.
mBpfDownstream4Map.updateEntry(key, value); if (downstream) {
} catch (ErrnoException e) { mBpfDownstream4Map.updateEntry(key, value);
mLog.e("Could not update entry: ", e); } else {
return false; mBpfUpstream4Map.updateEntry(key, value);
}
return true;
}
@Override
public boolean tetherOffloadRuleRemove(@NonNull Tether4Key key) {
if (!isInitialized()) return false;
try {
mBpfDownstream4Map.deleteEntry(key);
} catch (ErrnoException e) {
// Silent if the rule did not exist.
if (e.errno != OsConstants.ENOENT) {
mLog.e("Could not delete entry: ", e);
return false;
} }
}
return true;
}
@Override
public boolean tetherOffloadRuleAdd(@NonNull Tether4Key key,
@NonNull Tether4Value value) {
if (!isInitialized()) return false;
try {
// The last used time field of the value is updated by the bpf program. Adding the same
// map pair twice causes the unexpected refresh. Must be fixed before starting the
// conntrack timeout extension implementation.
// TODO: consider using insertEntry.
mBpfUpstream4Map.updateEntry(key, value);
} catch (ErrnoException e) { } catch (ErrnoException e) {
mLog.e("Could not update entry: ", e); mLog.e("Could not update entry: ", e);
return false; return false;
...@@ -300,11 +270,15 @@ public class BpfCoordinatorShimImpl ...@@ -300,11 +270,15 @@ public class BpfCoordinatorShimImpl
} }
@Override @Override
public boolean tetherOffloadRuleRemove(@NonNull Tether4Key key) { public boolean tetherOffloadRuleRemove(boolean downstream, @NonNull Tether4Key key) {
if (!isInitialized()) return false; if (!isInitialized()) return false;
try { try {
mBpfUpstream4Map.deleteEntry(key); if (downstream) {
mBpfDownstream4Map.deleteEntry(key);
} else {
mBpfUpstream4Map.deleteEntry(key);
}
} catch (ErrnoException e) { } catch (ErrnoException e) {
// Silent if the rule did not exist. // Silent if the rule did not exist.
if (e.errno != OsConstants.ENOENT) { if (e.errno != OsConstants.ENOENT) {
......
...@@ -112,25 +112,14 @@ public abstract class BpfCoordinatorShim { ...@@ -112,25 +112,14 @@ public abstract class BpfCoordinatorShim {
public abstract TetherStatsValue tetherOffloadGetAndClearStats(int ifIndex); public abstract TetherStatsValue tetherOffloadGetAndClearStats(int ifIndex);
/** /**
* Adds a tethering IPv4 downstream offload rule to BPF map. * Adds a tethering IPv4 offload rule to appropriate BPF map.
*/ */
public abstract boolean tetherOffloadRuleAdd(@NonNull Tether4Key key, public abstract boolean tetherOffloadRuleAdd(boolean downstream, @NonNull Tether4Key key,
@NonNull Tether4Value value); @NonNull Tether4Value value);
/** /**
* Deletes a tethering IPv4 downstream offload rule from the BPF map. * Deletes a tethering IPv4 offload rule from the appropriate BPF map.
*/ */
public abstract boolean tetherOffloadRuleRemove(@NonNull Tether4Key key); public abstract boolean tetherOffloadRuleRemove(boolean downstream, @NonNull Tether4Key key);
/**
* Adds a tethering IPv4 upstream offload rule to BPF map.
*/
public abstract boolean tetherOffloadRuleAdd(@NonNull Tether4Key key,
@NonNull Tether4Value value);
/**
* Deletes a tethering IPv4 upstream offload rule from the BPF map.
*/
public abstract boolean tetherOffloadRuleRemove(@NonNull Tether4Key key);
} }
...@@ -968,8 +968,8 @@ public class BpfCoordinator { ...@@ -968,8 +968,8 @@ public class BpfCoordinator {
if (e.msgType == (NetlinkConstants.NFNL_SUBSYS_CTNETLINK << 8 if (e.msgType == (NetlinkConstants.NFNL_SUBSYS_CTNETLINK << 8
| NetlinkConstants.IPCTNL_MSG_CT_DELETE)) { | NetlinkConstants.IPCTNL_MSG_CT_DELETE)) {
mBpfCoordinatorShim.tetherOffloadRuleRemove(upstream4Key); mBpfCoordinatorShim.tetherOffloadRuleRemove(false, upstream4Key);
mBpfCoordinatorShim.tetherOffloadRuleRemove(downstream4Key); mBpfCoordinatorShim.tetherOffloadRuleRemove(true, downstream4Key);
return; return;
} }
...@@ -978,8 +978,8 @@ public class BpfCoordinator { ...@@ -978,8 +978,8 @@ public class BpfCoordinator {
final Tether4Value downstream4Value = makeTether4Value(e, final Tether4Value downstream4Value = makeTether4Value(e,
tetherClient, upstreamIndex); tetherClient, upstreamIndex);
mBpfCoordinatorShim.tetherOffloadRuleAdd(upstream4Key, upstream4Value); mBpfCoordinatorShim.tetherOffloadRuleAdd(false, upstream4Key, upstream4Value);
mBpfCoordinatorShim.tetherOffloadRuleAdd(downstream4Key, downstream4Value); mBpfCoordinatorShim.tetherOffloadRuleAdd(true, downstream4Key, downstream4Value);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment