1c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
2c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Copyright (C) 2013 The Android Open Source Project
3c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
4c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Licensed under the Apache License, Version 2.0 (the "License");
5c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// you may not use this file except in compliance with the License.
6c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// You may obtain a copy of the License at
7c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
8c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//      http://www.apache.org/licenses/LICENSE-2.0
9c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
10c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Unless required by applicable law or agreed to in writing, software
11c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// distributed under the License is distributed on an "AS IS" BASIS,
12c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// See the License for the specific language governing permissions and
14c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// limitations under the License.
15c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
169da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
179da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal#ifndef SHILL_PPP_DEVICE_H_
189da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal#define SHILL_PPP_DEVICE_H_
199da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
20cc67c52a2c00f90e877971d552208dd99825d84eBen Chan#include <base/macros.h>
219da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
229da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal#include <map>
239da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal#include <string>
249da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
259da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal#include "shill/ipconfig.h"
269da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal#include "shill/virtual_device.h"
279da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
289da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalnamespace shill {
299da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
309da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal// Declared in the header to avoid linking unused code into shims.
319da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalstatic const char kPPPDNS1[] = "DNS1";
329da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalstatic const char kPPPDNS2[] = "DNS2";
339da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalstatic const char kPPPExternalIP4Address[] = "EXTERNAL_IP4_ADDRESS";
349da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalstatic const char kPPPGatewayAddress[] = "GATEWAY_ADDRESS";
359da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalstatic const char kPPPInterfaceName[] = "INTERNAL_IFNAME";
369da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalstatic const char kPPPInternalIP4Address[] = "INTERNAL_IP4_ADDRESS";
379da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalstatic const char kPPPLNSAddress[] = "LNS_ADDRESS";
3816ff6ebadd7854983a00000e07bd368a5aba305eGarret Kellystatic const char kPPPMRU[] = "MRU";
39fc362910150ab2abeb5556d4c02adc35cf2f7aa9mukesh agrawalstatic const char kPPPReasonAuthenticated[] = "authenticated";
40fc362910150ab2abeb5556d4c02adc35cf2f7aa9mukesh agrawalstatic const char kPPPReasonAuthenticating[] = "authenticating";
419da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalstatic const char kPPPReasonConnect[] = "connect";
429da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalstatic const char kPPPReasonDisconnect[] = "disconnect";
439da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
449da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawalclass PPPDevice : public VirtualDevice {
459da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal public:
461a212a6b98b22ad1d69652bb26a9e94138635476Paul Stewart  PPPDevice(ControlInterface* control,
471a212a6b98b22ad1d69652bb26a9e94138635476Paul Stewart            EventDispatcher* dispatcher,
481a212a6b98b22ad1d69652bb26a9e94138635476Paul Stewart            Metrics* metrics,
491a212a6b98b22ad1d69652bb26a9e94138635476Paul Stewart            Manager* manager,
501a212a6b98b22ad1d69652bb26a9e94138635476Paul Stewart            const std::string& link_name,
519da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal            int interface_index);
525ea763b83299b5fad76a87183fb39a74c2d3c61dBen Chan  ~PPPDevice() override;
539da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
549da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal  // Set IPConfig for this device, based on the dictionary of
559da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal  // configuration strings received from our PPP plugin.
569da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal  virtual void UpdateIPConfigFromPPP(
571a212a6b98b22ad1d69652bb26a9e94138635476Paul Stewart      const std::map<std::string, std::string>& configuration,
589da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal      bool blackhole_ipv6);
599da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
6034628593c4c51e8f1d393d6a03e3ebf06e4d9979Paul Stewart  // Same as UpdateIPConfigFromPPP except overriding the default MTU
6134628593c4c51e8f1d393d6a03e3ebf06e4d9979Paul Stewart  // in the IPConfig.
6234628593c4c51e8f1d393d6a03e3ebf06e4d9979Paul Stewart  virtual void UpdateIPConfigFromPPPWithMTU(
631a212a6b98b22ad1d69652bb26a9e94138635476Paul Stewart      const std::map<std::string, std::string>& configuration,
6434628593c4c51e8f1d393d6a03e3ebf06e4d9979Paul Stewart      bool blackhole_ipv6,
6534628593c4c51e8f1d393d6a03e3ebf06e4d9979Paul Stewart      int32_t mtu);
6634628593c4c51e8f1d393d6a03e3ebf06e4d9979Paul Stewart
67d1d3278b365e866a7381de2a640219b51fe0e27aPeter Qiu#ifndef DISABLE_DHCPV6
68d1d3278b365e866a7381de2a640219b51fe0e27aPeter Qiu  // Start a DHCPv6 configuration client for this device.  The generic
69d1d3278b365e866a7381de2a640219b51fe0e27aPeter Qiu  // file name (based on the device name) will be used for the acquired
70d1d3278b365e866a7381de2a640219b51fe0e27aPeter Qiu  // lease, so that the lease file will be removed when the DHCPv6 client
71d1d3278b365e866a7381de2a640219b51fe0e27aPeter Qiu  // terminates.  For PPP devices, there is no correlation between
72d1d3278b365e866a7381de2a640219b51fe0e27aPeter Qiu  // the service name and the network that it connected to.
73d1d3278b365e866a7381de2a640219b51fe0e27aPeter Qiu  virtual bool AcquireIPv6Config();
74d1d3278b365e866a7381de2a640219b51fe0e27aPeter Qiu#endif  // DISABLE_DHCPV6
75d1d3278b365e866a7381de2a640219b51fe0e27aPeter Qiu
769da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal  // Get the network device name (e.g. "ppp0") from the dictionary of
779da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal  // configuration strings received from our PPP plugin.
789da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal  static std::string GetInterfaceName(
791a212a6b98b22ad1d69652bb26a9e94138635476Paul Stewart      const std::map<std::string, std::string>& configuration);
809da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
819da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal private:
829da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal  FRIEND_TEST(PPPDeviceTest, GetInterfaceName);
839da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal  FRIEND_TEST(PPPDeviceTest, ParseIPConfiguration);
849da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
859dd6d6d37df195759f0f41239b4c4c1edd86c709Garret Kelly  IPConfig::Properties ParseIPConfiguration(
861a212a6b98b22ad1d69652bb26a9e94138635476Paul Stewart      const std::string& link_name,
871a212a6b98b22ad1d69652bb26a9e94138635476Paul Stewart      const std::map<std::string, std::string>& configuration);
889da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
899da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal  DISALLOW_COPY_AND_ASSIGN(PPPDevice);
909da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal};
919da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
929da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal}  // namespace shill
939da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal
949da07771df3dbbc99ff99114c26317d01f29f7fcmukesh agrawal#endif  // SHILL_PPP_DEVICE_H_
95