blob: 00d53451ab74b3c83d8c10ea834d9bd843dc2841 [file] [log] [blame]
Hugo Benichi7d9d8db2020-03-30 15:56:56 +09001// 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
5#ifndef ARC_NETWORK_ROUTING_SERVICE_H_
6#define ARC_NETWORK_ROUTING_SERVICE_H_
7
8#include <stdint.h>
9#include <sys/socket.h>
10
11#include <patchpanel/proto_bindings/patchpanel_service.pb.h>
12
13namespace arc_networkd {
14
15// Service implementing routing features of patchpanel.
16// TODO(hugobenichi) Explain how this coordinates with shill's RoutingTable.
17class 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
41} // namespace arc_networkd
42
43#endif // ARC_NETWORK_ROUTING_SERVICE_H_