blob: ef7a2942d008c9dbc241b8ee821dded3e0605dcc [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);
25 virtual ~MulticastProxy() = default;
26
27 protected:
28 int OnInit() override;
29
30 void OnParentProcessExit();
31 void OnDeviceMessage(const DeviceMessage& msg);
32
33 private:
34 void Reset();
35
36 MessageDispatcher msg_dispatcher_;
37 std::map<std::string, std::unique_ptr<MulticastForwarder>> mdns_fwds_;
38 std::map<std::string, std::unique_ptr<MulticastForwarder>> ssdp_fwds_;
39 std::map<std::string, std::unique_ptr<BroadcastForwarder>> bcast_fwds_;
40
41 base::WeakPtrFactory<MulticastProxy> weak_factory_{this};
42 DISALLOW_COPY_AND_ASSIGN(MulticastProxy);
43};
44
Garrick Evans3388a032020-03-24 11:25:55 +090045} // namespace patchpanel
Jason Jeremy Iman429b0792020-03-13 15:34:16 +090046
Garrick Evans3388a032020-03-24 11:25:55 +090047#endif // PATCHPANEL_MULTICAST_PROXY_H_