SecondaryTableController.h revision c462177bd58e3bf0ac4f618934dae060569e3e0b
1fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt/*
2fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt * Copyright (C) 2008 The Android Open Source Project
3fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt *
4fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt * Licensed under the Apache License, Version 2.0 (the "License");
5fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt * you may not use this file except in compliance with the License.
6fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt * You may obtain a copy of the License at
7fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt *
8fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt *      http://www.apache.org/licenses/LICENSE-2.0
9fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt *
10fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt * Unless required by applicable law or agreed to in writing, software
11fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt * distributed under the License is distributed on an "AS IS" BASIS,
12fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt * See the License for the specific language governing permissions and
14fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt * limitations under the License.
15fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt */
16fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
17fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt#ifndef _SECONDARY_TABLE_CONTROLLER_H
18fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt#define _SECONDARY_TABLE_CONTROLLER_H
19fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
20fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt#include <sysutils/FrameworkListener.h>
21fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
22fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwaltstatic const unsigned int MAX_IFACE_LENGTH = 10;
23fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwaltstatic const int INTERFACES_TRACKED = 10;
24fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwaltstatic const int BASE_TABLE_NUMBER = 60;
25fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwaltstatic int MAX_TABLE_NUMBER = BASE_TABLE_NUMBER + INTERFACES_TRACKED;
26fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
27fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwaltclass SecondaryTableController {
28fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
29fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwaltpublic:
30fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    SecondaryTableController();
31fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    virtual ~SecondaryTableController();
32fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
33fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    int addRoute(SocketClient *cli, char *iface, char *dest, int prefixLen, char *gateway);
34fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    int removeRoute(SocketClient *cli, char *iface, char *dest, int prefixLen, char *gateway);
35fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    int findTableNumber(const char *iface);
36c462177bd58e3bf0ac4f618934dae060569e3e0bRobert Greenwalt    int modifyFromRule(int tableIndex, const char *action, const char *addr);
37c462177bd58e3bf0ac4f618934dae060569e3e0bRobert Greenwalt    int modifyLocalRoute(int tableIndex, const char *action, const char *iface, const char *addr);
38fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
39fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwaltprivate:
40c462177bd58e3bf0ac4f618934dae060569e3e0bRobert Greenwalt    int modifyRoute(SocketClient *cli, const char *action, char *iface, char *dest, int prefix,
41063af322b48ab1bb0c3e09eb0b64915ba568275bRobert Greenwalt            char *gateway, int tableIndex);
42063af322b48ab1bb0c3e09eb0b64915ba568275bRobert Greenwalt
43fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    char mInterfaceTable[INTERFACES_TRACKED][MAX_IFACE_LENGTH];
44fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    int mInterfaceRuleCount[INTERFACES_TRACKED];
45c462177bd58e3bf0ac4f618934dae060569e3e0bRobert Greenwalt    void modifyRuleCount(int tableIndex, const char *action);
46c462177bd58e3bf0ac4f618934dae060569e3e0bRobert Greenwalt    int verifyTableIndex(int tableIndex);
47c462177bd58e3bf0ac4f618934dae060569e3e0bRobert Greenwalt    const char *getVersion(const char *addr);
48fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
49fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    int runAndFree(SocketClient *cli, char *cmd);
50fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt};
51fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
52fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt#endif
53