Home | History | Annotate | Download | only in ipv6proxy
      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 "socket.h"
     23 
     24 class Router {
     25 public:
     26     // Initialize the router, this has to be called before any other methods can
     27     // be called. It only needs to be called once.
     28     bool init();
     29 
     30     // Indicate that |address| is a neighbor to this node and that it is
     31     // accessible on the interface with index |interfaceIndex|.
     32     bool addNeighbor(const struct in6_addr& address, uint32_t interfaceIndex);
     33 
     34     // Add a route to |address|/|bits| on interface |interfaceIndex|. The
     35     // |bits| parameter indicates the bitmask of the address, for example in
     36     // the routing entry 2001:db8::/32 the |bits| parameter would be 32.
     37     bool addRoute(const struct in6_addr& address,
     38                   uint8_t bits,
     39                   uint32_t interfaceIndex);
     40 
     41     // Set the default gateway route to |address| on interface with index
     42     // |interfaceIndex|. Overwrites any existing default gateway with the same
     43     // address.
     44     bool setDefaultGateway(const struct in6_addr& address,
     45                            unsigned int interfaceIndex);
     46 private:
     47     bool sendNetlinkMessage(const void* data, size_t size);
     48 
     49     // Netlink socket for setting up neighbors and routes
     50     Socket mSocket;
     51 };
     52 
     53