Merge changes Ic4742bf5,I2c8a8e7f,I755a9a55,I2148bce6
* changes: NetworkProvider: improve documentation of unregisterNetworkOffer Revert "NetworkProvider: Do not propagate callbacks for unregistered offers" DscpPolicy: match_policy is_eth is always true DscpPolicy: remove bpf support for raw ip
This commit is contained in:
commit
944f9e3da1
3 changed files with 14 additions and 39 deletions
|
|
@ -53,12 +53,12 @@ DEFINE_BPF_MAP_GRW(ipv6_socket_to_policies_map_B, HASH, uint64_t, RuleEntry, MAX
|
|||
DEFINE_BPF_MAP_GRW(ipv4_dscp_policies_map, ARRAY, uint32_t, DscpPolicy, MAX_POLICIES, AID_SYSTEM)
|
||||
DEFINE_BPF_MAP_GRW(ipv6_dscp_policies_map, ARRAY, uint32_t, DscpPolicy, MAX_POLICIES, AID_SYSTEM)
|
||||
|
||||
static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4, bool is_eth) {
|
||||
static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4) {
|
||||
void* data = (void*)(long)skb->data;
|
||||
const void* data_end = (void*)(long)skb->data_end;
|
||||
|
||||
const int l2_header_size = is_eth ? sizeof(struct ethhdr) : 0;
|
||||
struct ethhdr* eth = is_eth ? data : NULL;
|
||||
const int l2_header_size = sizeof(struct ethhdr);
|
||||
struct ethhdr* eth = data;
|
||||
|
||||
if (data + l2_header_size > data_end) return;
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
|
|||
uint8_t priority = 0; // Only used for IPv6
|
||||
uint8_t flow_lbl = 0; // Only used for IPv6
|
||||
if (ipv4) {
|
||||
const struct iphdr* const iph = is_eth ? (void*)(eth + 1) : data;
|
||||
const struct iphdr* const iph = (void*)(eth + 1);
|
||||
hdr_size = l2_header_size + sizeof(struct iphdr);
|
||||
// Must have ipv4 header
|
||||
if (data + hdr_size > data_end) return;
|
||||
|
|
@ -105,7 +105,7 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
|
|||
protocol = iph->protocol;
|
||||
tos = iph->tos;
|
||||
} else {
|
||||
struct ipv6hdr* ip6h = is_eth ? (void*)(eth + 1) : data;
|
||||
struct ipv6hdr* ip6h = (void*)(eth + 1);
|
||||
hdr_size = l2_header_size + sizeof(struct ipv6hdr);
|
||||
// Must have ipv6 header
|
||||
if (data + hdr_size > data_end) return;
|
||||
|
|
@ -293,22 +293,9 @@ DEFINE_BPF_PROG_KVER("schedcls/set_dscp_ether", AID_ROOT, AID_SYSTEM,
|
|||
if (skb->pkt_type != PACKET_HOST) return TC_ACT_PIPE;
|
||||
|
||||
if (skb->protocol == htons(ETH_P_IP)) {
|
||||
match_policy(skb, true, true);
|
||||
match_policy(skb, true);
|
||||
} else if (skb->protocol == htons(ETH_P_IPV6)) {
|
||||
match_policy(skb, false, true);
|
||||
}
|
||||
|
||||
// Always return TC_ACT_PIPE
|
||||
return TC_ACT_PIPE;
|
||||
}
|
||||
|
||||
DEFINE_BPF_PROG_KVER("schedcls/set_dscp_raw_ip", AID_ROOT, AID_SYSTEM,
|
||||
schedcls_set_dscp_raw_ip, KVER(5, 15, 0))
|
||||
(struct __sk_buff* skb) {
|
||||
if (skb->protocol == htons(ETH_P_IP)) {
|
||||
match_policy(skb, true, false);
|
||||
} else if (skb->protocol == htons(ETH_P_IPV6)) {
|
||||
match_policy(skb, false, false);
|
||||
match_policy(skb, false);
|
||||
}
|
||||
|
||||
// Always return TC_ACT_PIPE
|
||||
|
|
|
|||
|
|
@ -192,36 +192,21 @@ public class NetworkProvider {
|
|||
private class NetworkOfferCallbackProxy extends INetworkOfferCallback.Stub {
|
||||
@NonNull public final NetworkOfferCallback callback;
|
||||
@NonNull private final Executor mExecutor;
|
||||
/**
|
||||
* Boolean flag that prevents onNetworkNeeded / onNetworkUnneeded callbacks from being
|
||||
* propagated after unregisterNetworkOffer has been called. Since unregisterNetworkOffer
|
||||
* runs on the CS handler thread, it will not go into effect immediately.
|
||||
*/
|
||||
private volatile boolean mIsStale;
|
||||
|
||||
NetworkOfferCallbackProxy(@NonNull final NetworkOfferCallback callback,
|
||||
@NonNull final Executor executor) {
|
||||
this.callback = callback;
|
||||
this.mExecutor = executor;
|
||||
this.mIsStale = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetworkNeeded(final @NonNull NetworkRequest request) {
|
||||
mExecutor.execute(() -> {
|
||||
if (!mIsStale) callback.onNetworkNeeded(request);
|
||||
});
|
||||
mExecutor.execute(() -> callback.onNetworkNeeded(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetworkUnneeded(final @NonNull NetworkRequest request) {
|
||||
mExecutor.execute(() -> {
|
||||
if (!mIsStale) callback.onNetworkUnneeded(request);
|
||||
});
|
||||
}
|
||||
|
||||
public void markStale() {
|
||||
mIsStale = true;
|
||||
mExecutor.execute(() -> callback.onNetworkUnneeded(request));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -334,6 +319,11 @@ public class NetworkProvider {
|
|||
* if it could beat any of them, and may be advantageous to the provider's implementation that
|
||||
* can rely on no longer receiving callbacks for a network that they can't bring up anyways.
|
||||
*
|
||||
* Warning: This method executes asynchronously. The NetworkOfferCallback object can continue
|
||||
* receiving onNetworkNeeded and onNetworkUnneeded callbacks even after this method has
|
||||
* returned. In this case, it is on the caller to take appropriate steps in order to prevent
|
||||
* bringing up a network.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
|
|
@ -342,7 +332,6 @@ public class NetworkProvider {
|
|||
final NetworkOfferCallbackProxy proxy = findProxyForCallback(callback);
|
||||
if (null == proxy) return;
|
||||
synchronized (mProxies) {
|
||||
proxy.markStale();
|
||||
mProxies.remove(proxy);
|
||||
}
|
||||
mContext.getSystemService(ConnectivityManager.class).unofferNetwork(proxy);
|
||||
|
|
|
|||
|
|
@ -127,7 +127,6 @@ static const set<string> MAINLINE_FOR_T_5_4_PLUS = {
|
|||
// Provided by *current* mainline module for T+ devices with 5.15+ kernels
|
||||
static const set<string> MAINLINE_FOR_T_5_15_PLUS = {
|
||||
SHARED "prog_dscpPolicy_schedcls_set_dscp_ether",
|
||||
SHARED "prog_dscpPolicy_schedcls_set_dscp_raw_ip",
|
||||
};
|
||||
|
||||
void addAll(set<string>* a, const set<string>& b) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue