Skip to content

Commit

Permalink
LibNL policy for minmdns.
Browse files Browse the repository at this point in the history
- ability to compile with it
- target for minmdns examples
- fix minmdns examples to pick up default policies
  • Loading branch information
andy31415 committed Aug 29, 2022
1 parent b90a934 commit 5394d7f
Show file tree
Hide file tree
Showing 9 changed files with 519 additions and 12 deletions.
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>
#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
10 changes: 6 additions & 4 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,18 +199,20 @@ 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");

mdns::Minimal::QueryResponder<16 /* maxRecords */> queryResponder;

mdns::Minimal::QNamePart tcpServiceName[] = { Dnssd::kOperationalServiceName, Dnssd::kOperationalProtocol,
Dnssd::kLocalDomain };
Dnssd::kLocalDomain };
mdns::Minimal::QNamePart tcpServerServiceName[] = { gOptions.instanceName, Dnssd::kOperationalServiceName,
Dnssd::kOperationalProtocol, Dnssd::kLocalDomain };
mdns::Minimal::QNamePart udpServiceName[] = { Dnssd::kCommissionableServiceName, Dnssd::kCommissionProtocol,
Dnssd::kLocalDomain };
Dnssd::kLocalDomain };
mdns::Minimal::QNamePart udpServerServiceName[] = { gOptions.instanceName, Dnssd::kCommissionableServiceName,
Dnssd::kCommissionProtocol, Dnssd::kLocalDomain };

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
7 changes: 7 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,12 @@ 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')
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
#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

0 comments on commit 5394d7f

Please sign in to comment.