blob: 259ab433293585aa68a3e3570344c2247dc3edf4 [file] [log] [blame]
Robert Greenwaltfc97b822011-11-02 16:48:36 -07001/*
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
22static const unsigned int MAX_IFACE_LENGTH = 10;
23static const int INTERFACES_TRACKED = 10;
24static const int BASE_TABLE_NUMBER = 60;
25static int MAX_TABLE_NUMBER = BASE_TABLE_NUMBER + INTERFACES_TRACKED;
26
27class SecondaryTableController {
28
29public:
30 SecondaryTableController();
31 virtual ~SecondaryTableController();
32
33 int addRoute(SocketClient *cli, char *iface, char *dest, int prefixLen, char *gateway);
34 int removeRoute(SocketClient *cli, char *iface, char *dest, int prefixLen, char *gateway);
35 int findTableNumber(const char *iface);
Robert Greenwaltc4621772012-01-31 12:46:45 -080036 int modifyFromRule(int tableIndex, const char *action, const char *addr);
37 int modifyLocalRoute(int tableIndex, const char *action, const char *iface, const char *addr);
Robert Greenwaltfc97b822011-11-02 16:48:36 -070038
39private:
Robert Greenwaltc4621772012-01-31 12:46:45 -080040 int modifyRoute(SocketClient *cli, const char *action, char *iface, char *dest, int prefix,
Robert Greenwalt063af322011-11-18 15:32:13 -080041 char *gateway, int tableIndex);
42
Robert Greenwaltfc97b822011-11-02 16:48:36 -070043 char mInterfaceTable[INTERFACES_TRACKED][MAX_IFACE_LENGTH];
44 int mInterfaceRuleCount[INTERFACES_TRACKED];
Robert Greenwaltc4621772012-01-31 12:46:45 -080045 void modifyRuleCount(int tableIndex, const char *action);
46 int verifyTableIndex(int tableIndex);
47 const char *getVersion(const char *addr);
Robert Greenwaltfc97b822011-11-02 16:48:36 -070048
49 int runAndFree(SocketClient *cli, char *cmd);
50};
51
52#endif