blob: b0044aa46bbadbd5784548fc9baecd0b9cfa7173 [file] [log] [blame]
Ningyuan Wangb6836022015-12-02 14:39:01 -08001//
2// Copyright (C) 2015 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
17#ifndef DHCP_CLIENT_SERVICE_H_
18#define DHCP_CLIENT_SERVICE_H_
19
20#include <string>
21
22#include <base/macros.h>
23#include <base/memory/ref_counted.h>
24#include <brillo/variant_dictionary.h>
25
Ningyuan Wangb52786a2015-12-10 14:25:15 -080026#include "dhcp_client/dhcp.h"
27#include "dhcp_client/dhcpv4.h"
Ningyuan Wangb6836022015-12-02 14:39:01 -080028#include "dhcp_client/event_dispatcher_interface.h"
Ningyuan Wang63aa9b52016-01-19 10:24:59 -080029#include "shill/net/byte_string.h"
Ningyuan Wangb6836022015-12-02 14:39:01 -080030
31namespace dhcp_client {
32
33class Manager;
34
35class Service : public base::RefCounted<Service> {
36 public:
37 Service(Manager* manager,
38 int service_identifier,
39 EventDispatcherInterface* event_dispatcher,
40 const brillo::VariantDictionary& configs);
41
42 virtual ~Service();
Ningyuan Wangb52786a2015-12-10 14:25:15 -080043 bool Start();
Ningyuan Wangb6836022015-12-02 14:39:01 -080044 void Stop();
45
46 private:
47 Manager* manager_;
Ningyuan Wangab2af972015-12-03 13:57:40 -080048 // Indentifier number of this service.
Ningyuan Wangb6836022015-12-02 14:39:01 -080049 int identifier_;
50 EventDispatcherInterface* event_dispatcher_;
Ningyuan Wangb52786a2015-12-10 14:25:15 -080051 // Interface parameters.
Ningyuan Wangb6836022015-12-02 14:39:01 -080052 std::string interface_name_;
Ningyuan Wang63aa9b52016-01-19 10:24:59 -080053 shill::ByteString hardware_address_;
Ningyuan Wangb52786a2015-12-10 14:25:15 -080054 unsigned int interface_index_;
55
Ningyuan Wangab2af972015-12-03 13:57:40 -080056 // Unique network/connection identifier,
57 // lease will persist to storage if this identifier is specified.
Ningyuan Wangb6836022015-12-02 14:39:01 -080058 std::string network_id_;
59
Ningyuan Wangb52786a2015-12-10 14:25:15 -080060 // Type of the DHCP service.
61 // It can be IPv4 only or IPv6 only or both.
62 DHCP::ServiceType type_;
63
Ningyuan Wangb6836022015-12-02 14:39:01 -080064 // DHCP IPv4 configurations:
Ningyuan Wangab2af972015-12-03 13:57:40 -080065 // Request hostname from server.
Ningyuan Wangb6836022015-12-02 14:39:01 -080066 bool request_hostname_;
Ningyuan Wangab2af972015-12-03 13:57:40 -080067 // ARP for default gateway.
Ningyuan Wangb6836022015-12-02 14:39:01 -080068 bool arp_gateway_;
Ningyuan Wangab2af972015-12-03 13:57:40 -080069 // Enable unicast ARP on renew.
Ningyuan Wangb6836022015-12-02 14:39:01 -080070 bool unicast_arp_;
71
72 // DHCP IPv6 configurations:
Ningyuan Wangab2af972015-12-03 13:57:40 -080073 // Request non-temporary address.
Ningyuan Wangb6836022015-12-02 14:39:01 -080074 bool request_na_;
Ningyuan Wangab2af972015-12-03 13:57:40 -080075 // Request prefix delegation.
Ningyuan Wangb6836022015-12-02 14:39:01 -080076 bool request_pd_;
Ningyuan Wangb52786a2015-12-10 14:25:15 -080077
78 std::unique_ptr<DHCPV4> state_machine_ipv4_;
Ningyuan Wangab2af972015-12-03 13:57:40 -080079 // Parse DHCP configurations from the VariantDictionary.
Ningyuan Wangb6836022015-12-02 14:39:01 -080080 void ParseConfigs(const brillo::VariantDictionary& configs);
81
82 DISALLOW_COPY_AND_ASSIGN(Service);
83};
84
85} // namespace dhcp_client
86
87#endif // DHCP_CLIENT_SERVICE_H_