Home | History | Annotate | Download | only in netd
      1 /*
      2  * Copyright (C) 2010 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 #ifndef _DNSPROXYLISTENER_H__
     18 #define _DNSPROXYLISTENER_H__
     19 
     20 #include <sysutils/FrameworkListener.h>
     21 
     22 #include "NetdCommand.h"
     23 #include "UidMarkMap.h"
     24 
     25 class DnsProxyListener : public FrameworkListener {
     26 public:
     27     DnsProxyListener(UidMarkMap *map);
     28     virtual ~DnsProxyListener() {}
     29 
     30 private:
     31     UidMarkMap *mUidMarkMap;
     32     class GetAddrInfoCmd : public NetdCommand {
     33     public:
     34         GetAddrInfoCmd(UidMarkMap *uidMarkMap);
     35         virtual ~GetAddrInfoCmd() {}
     36         int runCommand(SocketClient *c, int argc, char** argv);
     37     private:
     38         UidMarkMap *mUidMarkMap;
     39     };
     40 
     41     class GetAddrInfoHandler {
     42     public:
     43         // Note: All of host, service, and hints may be NULL
     44         GetAddrInfoHandler(SocketClient *c,
     45                            char* host,
     46                            char* service,
     47                            struct addrinfo* hints,
     48                            char* iface,
     49                            pid_t pid,
     50                            uid_t uid,
     51                            int mark);
     52         ~GetAddrInfoHandler();
     53 
     54         static void* threadStart(void* handler);
     55         void start();
     56 
     57     private:
     58         void run();
     59         SocketClient* mClient;  // ref counted
     60         char* mHost;    // owned
     61         char* mService; // owned
     62         struct addrinfo* mHints;  // owned
     63         char* mIface; // owned
     64         pid_t mPid;
     65         uid_t mUid;
     66         int mMark;
     67     };
     68 
     69     /* ------ gethostbyname ------*/
     70     class GetHostByNameCmd : public NetdCommand {
     71     public:
     72         GetHostByNameCmd(UidMarkMap *uidMarkMap);
     73         virtual ~GetHostByNameCmd() {}
     74         int runCommand(SocketClient *c, int argc, char** argv);
     75     private:
     76         UidMarkMap *mUidMarkMap;
     77     };
     78 
     79     class GetHostByNameHandler {
     80     public:
     81         GetHostByNameHandler(SocketClient *c,
     82                             pid_t pid,
     83                             uid_t uid,
     84                             char *iface,
     85                             char *name,
     86                             int af,
     87                             int mark);
     88         ~GetHostByNameHandler();
     89         static void* threadStart(void* handler);
     90         void start();
     91     private:
     92         void run();
     93         SocketClient* mClient; //ref counted
     94         pid_t mPid;
     95         uid_t mUid;
     96         char* mIface; // owned
     97         char* mName; // owned
     98         int mAf;
     99         int mMark;
    100     };
    101 
    102     /* ------ gethostbyaddr ------*/
    103     class GetHostByAddrCmd : public NetdCommand {
    104     public:
    105         GetHostByAddrCmd(UidMarkMap *uidMarkMap);
    106         virtual ~GetHostByAddrCmd() {}
    107         int runCommand(SocketClient *c, int argc, char** argv);
    108     private:
    109         UidMarkMap *mUidMarkMap;
    110     };
    111 
    112     class GetHostByAddrHandler {
    113     public:
    114         GetHostByAddrHandler(SocketClient *c,
    115                             void* address,
    116                             int   addressLen,
    117                             int   addressFamily,
    118                             char* iface,
    119                             pid_t pid,
    120                             uid_t uid,
    121                             int mark);
    122         ~GetHostByAddrHandler();
    123 
    124         static void* threadStart(void* handler);
    125         void start();
    126 
    127     private:
    128         void run();
    129         SocketClient* mClient;  // ref counted
    130         void* mAddress;    // address to lookup; owned
    131         int   mAddressLen; // length of address to look up
    132         int   mAddressFamily;  // address family
    133         char* mIface; // owned
    134         pid_t mPid;
    135         uid_t mUid;
    136         int   mMark;
    137     };
    138 };
    139 
    140 #endif
    141