SecondaryTableController.h revision 3c20787d7935c2016e8e3cc49d8f15647c12c41c
1/*
2 * Copyright (C) 2008 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 _SECONDARY_TABLE_CONTROLLER_H
18#define _SECONDARY_TABLE_CONTROLLER_H
19
20#include <sysutils/FrameworkListener.h>
21
22#include <linux/if.h>
23
24#ifndef IFNAMSIZ
25#define IFNAMSIZ 16
26#endif
27
28static const int INTERFACES_TRACKED = 10;
29static const int BASE_TABLE_NUMBER = 60;
30static int MAX_TABLE_NUMBER = BASE_TABLE_NUMBER + INTERFACES_TRACKED;
31
32class SecondaryTableController {
33
34public:
35    SecondaryTableController();
36    virtual ~SecondaryTableController();
37
38    int addRoute(SocketClient *cli, char *iface, char *dest, int prefixLen, char *gateway);
39    int removeRoute(SocketClient *cli, char *iface, char *dest, int prefixLen, char *gateway);
40    int findTableNumber(const char *iface);
41
42private:
43    int modifyRoute(SocketClient *cli, char *action, char *iface, char *dest, int prefix,
44            char *gateway, int tableIndex);
45
46    char mInterfaceTable[INTERFACES_TRACKED][IFNAMSIZ + 1];
47    int mInterfaceRuleCount[INTERFACES_TRACKED];
48
49    int runAndFree(SocketClient *cli, char *cmd);
50};
51
52#endif
53