1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <aidl/android/hardware/net/nlinterceptor/BnInterceptor.h>
20 #include <libnlinterceptor/libnlinterceptor.h>
21 
22 #include <map>
23 
24 #include "InterceptorRelay.h"
25 
26 namespace android::nlinterceptor {
27 
28 class NetlinkInterceptor
29     : public ::aidl::android::hardware::net::nlinterceptor::BnInterceptor {
30     using ClientMap =
31         std::map<::android::nlinterceptor::InterceptedSocket,
32                  std::unique_ptr<::android::nlinterceptor::InterceptorRelay>>;
33 
34     using AidlInterceptedSocket =
35         ::aidl::android::hardware::net::nlinterceptor::InterceptedSocket;
36 
37    public:
38     ndk::ScopedAStatus createSocket(
39         int32_t nlFamily, int32_t clientNlPid, const std::string& clientName,
40         AidlInterceptedSocket* interceptedSocket) override;
41 
42     ndk::ScopedAStatus closeSocket(
43         const AidlInterceptedSocket& interceptedSocket) override;
44 
45     ndk::ScopedAStatus subscribeGroup(
46         const AidlInterceptedSocket& interceptedSocket,
47         int32_t nlGroup) override;
48 
49     ndk::ScopedAStatus unsubscribeGroup(
50         const AidlInterceptedSocket& interceptedSocket,
51         int32_t nlGroup) override;
52 
53    private:
54     ClientMap mClientMap;
55 };
56 
57 }  // namespace android::nlinterceptor
58