Skip to content

Commit

Permalink
MinMDNS available policy: libnl (#22246)
Browse files Browse the repository at this point in the history
* LibNL policy for minmdns.

- ability to compile with it
- target for minmdns examples
- fix minmdns examples to pick up default policies

* Depend libnl build on it being actually compiled in

* Restyle
  • Loading branch information
andy31415 authored and pull[bot] committed Dec 13, 2023
1 parent c753c76 commit 4885249
Show file tree
Hide file tree
Showing 9 changed files with 516 additions and 10 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
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 @@ -283,6 +283,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')
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 4885249

Please sign in to comment.