Hugo Benichi | 7d9d8db | 2020-03-30 15:56:56 +0900 | [diff] [blame] | 1 | // Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 5 | #ifndef PATCHPANEL_ROUTING_SERVICE_H_ |
| 6 | #define PATCHPANEL_ROUTING_SERVICE_H_ |
Hugo Benichi | 7d9d8db | 2020-03-30 15:56:56 +0900 | [diff] [blame] | 7 | |
| 8 | #include <stdint.h> |
| 9 | #include <sys/socket.h> |
| 10 | |
| 11 | #include <patchpanel/proto_bindings/patchpanel_service.pb.h> |
| 12 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 13 | namespace patchpanel { |
Hugo Benichi | 7d9d8db | 2020-03-30 15:56:56 +0900 | [diff] [blame] | 14 | |
| 15 | // Service implementing routing features of patchpanel. |
| 16 | // TODO(hugobenichi) Explain how this coordinates with shill's RoutingTable. |
| 17 | class RoutingService { |
| 18 | public: |
| 19 | RoutingService(); |
| 20 | RoutingService(const RoutingService&) = delete; |
| 21 | RoutingService& operator=(const RoutingService&) = delete; |
| 22 | virtual ~RoutingService() = default; |
| 23 | |
| 24 | // Sets the VPN bits of the fwmark for the given socket according to the |
| 25 | // given policy. Preserves any other bits of the fwmark already set. |
| 26 | bool SetVpnFwmark(int sockfd, |
| 27 | patchpanel::SetVpnIntentRequest::VpnRoutingPolicy policy); |
| 28 | |
| 29 | // Sets the fwmark on the given socket with the given mask. |
| 30 | // Preserves any other bits of the fwmark already set. |
| 31 | bool SetFwmark(int sockfd, uint32_t mark, uint32_t mask); |
| 32 | |
| 33 | protected: |
| 34 | // Can be overridden in tests. |
| 35 | virtual int GetSockopt( |
| 36 | int sockfd, int level, int optname, void* optval, socklen_t* optlen); |
| 37 | virtual int SetSockopt( |
| 38 | int sockfd, int level, int optname, const void* optval, socklen_t optlen); |
| 39 | }; |
| 40 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 41 | } // namespace patchpanel |
Hugo Benichi | 7d9d8db | 2020-03-30 15:56:56 +0900 | [diff] [blame] | 42 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame^] | 43 | #endif // PATCHPANEL_ROUTING_SERVICE_H_ |