blob: 89ad53d9702adf54d4cabd8712dfeb977428856c [file] [log] [blame]
Jason Jeremy Iman429b0792020-03-13 15:34:16 +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_MULTICAST_PROXY_H_
6#define PATCHPANEL_MULTICAST_PROXY_H_
Jason Jeremy Iman429b0792020-03-13 15:34:16 +09007
8#include <map>
9#include <memory>
10#include <string>
11
12#include <brillo/daemons/daemon.h>
13
Garrick Evans3388a032020-03-24 11:25:55 +090014#include "patchpanel/broadcast_forwarder.h"
15#include "patchpanel/message_dispatcher.h"
16#include "patchpanel/multicast_forwarder.h"
Jason Jeremy Iman429b0792020-03-13 15:34:16 +090017
Garrick Evans3388a032020-03-24 11:25:55 +090018namespace patchpanel {
Jason Jeremy Iman429b0792020-03-13 15:34:16 +090019
20// MulticastProxy manages multiple MulticastForwarder instances to forward
21// multicast for multiple physical interfaces.
22class MulticastProxy : public brillo::Daemon {
23 public:
24 explicit MulticastProxy(base::ScopedFD control_fd);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090025 MulticastProxy(const MulticastProxy&) = delete;
26 MulticastProxy& operator=(const MulticastProxy&) = delete;
27
Jason Jeremy Iman429b0792020-03-13 15:34:16 +090028 virtual ~MulticastProxy() = default;
29
30 protected:
31 int OnInit() override;
32
33 void OnParentProcessExit();
34 void OnDeviceMessage(const DeviceMessage& msg);
35
36 private:
37 void Reset();
38
39 MessageDispatcher msg_dispatcher_;
40 std::map<std::string, std::unique_ptr<MulticastForwarder>> mdns_fwds_;
41 std::map<std::string, std::unique_ptr<MulticastForwarder>> ssdp_fwds_;
42 std::map<std::string, std::unique_ptr<BroadcastForwarder>> bcast_fwds_;
43
44 base::WeakPtrFactory<MulticastProxy> weak_factory_{this};
Jason Jeremy Iman429b0792020-03-13 15:34:16 +090045};
46
Garrick Evans3388a032020-03-24 11:25:55 +090047} // namespace patchpanel
Jason Jeremy Iman429b0792020-03-13 15:34:16 +090048
Garrick Evans3388a032020-03-24 11:25:55 +090049#endif // PATCHPANEL_MULTICAST_PROXY_H_