Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinMDNS available policy: libnl #22246

Merged
merged 3 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/minimal-mdns/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ executable("minimal-mdns-server") {
":minimal-mdns-example-common",
"${chip_root}/src/lib",
"${chip_root}/src/lib/dnssd/minimal_mdns",
"${chip_root}/src/lib/dnssd/minimal_mdns:default_policy",
"${chip_root}/src/lib/dnssd/minimal_mdns/responders",
]

Expand Down
7 changes: 5 additions & 2 deletions examples/minimal-mdns/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

#include <inet/InetInterface.h>
#include <inet/UDPEndPoint.h>
#include <lib/dnssd/MinimalMdnsServer.h>
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
#include <lib/dnssd/minimal_mdns/AddressPolicy.h>
#include <lib/dnssd/minimal_mdns/AddressPolicy_DefaultImpl.h>
#include <lib/dnssd/minimal_mdns/QueryBuilder.h>
#include <lib/dnssd/minimal_mdns/Server.h>
#include <lib/dnssd/minimal_mdns/core/QName.h>
Expand Down Expand Up @@ -315,7 +315,10 @@ int main(int argc, char ** args)
ReportDelegate reporter;
CHIP_ERROR err;

mdns::Minimal::SetDefaultAddressPolicy();
// This forces the global MDNS instance to be loaded in, effectively setting
// built in policies for addresses.
(void) chip::Dnssd::GlobalMinimalMdnsServer::Instance();

gMdnsServer.SetDelegate(&reporter);

{
Expand Down
6 changes: 4 additions & 2 deletions examples/minimal-mdns/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

#include <inet/InetInterface.h>
#include <inet/UDPEndPoint.h>
#include <lib/dnssd/MinimalMdnsServer.h>
#include <lib/dnssd/ServiceNaming.h>
#include <lib/dnssd/minimal_mdns/AddressPolicy.h>
#include <lib/dnssd/minimal_mdns/AddressPolicy_DefaultImpl.h>
#include <lib/dnssd/minimal_mdns/QueryBuilder.h>
#include <lib/dnssd/minimal_mdns/ResponseSender.h>
#include <lib/dnssd/minimal_mdns/Server.h>
Expand Down Expand Up @@ -199,7 +199,9 @@ int main(int argc, char ** args)
return 1;
}

mdns::Minimal::SetDefaultAddressPolicy();
// This forces the global MDNS instance to be loaded in, effectively setting
// built in policies for addresses.
(void) chip::Dnssd::GlobalMinimalMdnsServer::Instance();

printf("Running on port %d using %s...\n", gOptions.listenPort, gOptions.enableIpV4 ? "IPv4 AND IPv6" : "IPv6 ONLY");

Expand Down
2 changes: 2 additions & 0 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ def HostTargets():

# Possible build variants. Note that number of potential
# builds is exponential here
builder.AppendVariant(name="libnl", validator=AcceptNameWithSubstrings(
['-minmdns']), minmdns_address_policy="libnl"),
builder.AppendVariant(name="same-event-loop", validator=AcceptNameWithSubstrings(
['-chip-tool', '-darwin-framework-tool']), separate_event_loop=False),
builder.AppendVariant(name="no-interactive", validator=AcceptNameWithSubstrings(
Expand Down
6 changes: 6 additions & 0 deletions scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
interactive_mode=True, extra_tests=False,
use_platform_mdns=False, enable_rpcs=False,
use_coverage=False, use_dmalloc=False,
minmdns_address_policy=None,
crypto_library: HostCryptoLibrary = None):
super(HostBuilder, self).__init__(
root=os.path.join(root, 'examples', app.ExamplePath()),
Expand Down Expand Up @@ -280,6 +281,11 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
# so setting clang is not correct
raise Exception('Fake host board is always gcc (not clang)')

if minmdns_address_policy:
if use_platform_mdns:
raise Exception('Address policy applies to minmdns only')
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
self.extra_gn_options.append('chip_minmdns_default_policy="%s"' % minmdns_address_policy)

if use_platform_mdns:
self.extra_gn_options.append('chip_mdns="platform"')

Expand Down
14 changes: 13 additions & 1 deletion src/lib/dnssd/MinimalMdnsServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@
#define CHIP_MINMDNS_DEFAULT_POLICY 0
#endif

#ifndef CHIP_MINMDNS_LIBNL_POLICY
#define CHIP_MINMDNS_LIBNL_POLICY 0
#endif

#if CHIP_MINMDNS_DEFAULT_POLICY
#include <lib/dnssd/minimal_mdns/AddressPolicy_DefaultImpl.h>
#include <lib/dnssd/minimal_mdns/AddressPolicy_DefaultImpl.h> // nogncheck
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
#endif

#if CHIP_MINMDNS_LIBNL_POLICY
#include <lib/dnssd/minimal_mdns/AddressPolicy_LibNlImpl.h> // nogncheck
#endif

namespace chip {
Expand All @@ -39,6 +47,10 @@ GlobalMinimalMdnsServer::GlobalMinimalMdnsServer()
#if CHIP_MINMDNS_DEFAULT_POLICY
mdns::Minimal::SetDefaultAddressPolicy();
#endif

#if CHIP_MINMDNS_LIBNL_POLICY
mdns::Minimal::LibNl::SetAddressPolicy();
#endif
}

GlobalMinimalMdnsServer & GlobalMinimalMdnsServer::Instance()
Expand Down
Loading