blob: cda7b661f98b7c43ad6ad6845daa770977f3a84c [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
Garrick Evans3388a032020-03-24 11:25:55 +09005#ifndef PATCHPANEL_ROUTING_SERVICE_H_
6#define PATCHPANEL_ROUTING_SERVICE_H_
Hugo Benichi7d9d8db2020-03-30 15:56:56 +09007
8#include <stdint.h>
9#include <sys/socket.h>
10
11#include <patchpanel/proto_bindings/patchpanel_service.pb.h>
12
Garrick Evans3388a032020-03-24 11:25:55 +090013namespace patchpanel {
Hugo Benichi7d9d8db2020-03-30 15:56:56 +090014
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
Garrick Evans3388a032020-03-24 11:25:55 +090041} // namespace patchpanel
Hugo Benichi7d9d8db2020-03-30 15:56:56 +090042
Garrick Evans3388a032020-03-24 11:25:55 +090043#endif // PATCHPANEL_ROUTING_SERVICE_H_