• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 #pragma once
17 
18 #include <stdint.h>
19 
20 #include <netinet/in.h>
21 
22 #include "result.h"
23 
24 class Router {
25 public:
26     Router();
27     ~Router();
28     // Initialize the router, this has to be called before any other methods can
29     // be called. It only needs to be called once.
30     Result init();
31 
32     // Set the default route to |gateway| on the interface specified by
33     // |interfaceIndex|. If the default route is already set up with the same
34     // configuration then nothing is done. If another default route exists it
35     // will be removed and replaced by the new one. If no default route exists
36     // a route will be created with the given parameters.
37     Result setDefaultGateway(in_addr_t gateway, unsigned int interfaceIndex);
38 private:
39     Result sendNetlinkMessage(const void* data, size_t size);
40 
41     // Netlink socket for setting up neighbors and routes
42     int mSocketFd;
43 };
44 
45