diff mbox series

umdns: add timeout_lookup parameter for services

Message ID CAAAtp75Fm8OaVryfDZty2bvCCMOh8pns0PXv+LpXpxcXU7hc3A@mail.gmail.com
State New
Headers show
Series umdns: add timeout_lookup parameter for services | expand

Commit Message

Tobias Waldvogel Aug. 26, 2022, 11:40 a.m. UTC
From: Tobias Waldvogel <tobias.waldvogel@gmail.com>

Printing on Android devices via mdns IPP does not work
with the default value of 60 seconds for the
lookup timeout. It seems that Androd expects an
immediate answer just when trying to print. Nevertheless
the umdns debug messages show that the answer is supressed
due to the timeout. As a result the printer does not
show up.
This patch implements an additional parameter
timeout_lookup for setting a dedicated timeout value
with a fallback to TOUT_LOOKUP (60s).

This is a sample ipp service definition, which works
now with Android standard printing:

{
  "ipp": {
    "service": "_ipp._tcp.local",
    "instance": "HL3040CN @ router",
    "port": 631,
    "timeout_lookup": -1,
    "txt": [
      "txtvers=1",
      "UUID=308f65f9-5393-3027-4c83-374cb704e729",
      "rp=printers/HL3040CN",
      "ty=Brother HL3040CN",
      "note=Office",
      "pdl=application/pdf,image/jpeg,image/png,image/pwg-raster",
      "Color=T",
      "Copies=T"
    ]
  }
}

Signed-off-by: Tobias Waldvogel <tobias.waldvogel@gmail.com>
---
  [SERVICE_PORT] = { .name = "port", .type = BLOBMSG_TYPE_INT32 },
@@ -122,8 +125,8 @@ service_timeout(struct service *s)
 {
  time_t t = monotonic_time();

- if (t - s->t <= TOUT_LOOKUP) {
- DBG(2, "t=%" PRId64 ", s->t=%" PRId64 ", t - s->t = %" PRId64 "\n",
(int64_t)t, (int64_t)s->t, (int64_t)(t - s->t));
+ if (t - s->t <= s->tout_lookup) {
+ DBG(2, "t=%" PRId64 ", s->t=%" PRId64 ", s->tout_lookup=%d, t - s->t
= %" PRId64 "\n", (int64_t)t, (int64_t)s->t, s->tout_lookup,
(int64_t)(t - s->t));
  return 0;
  }

@@ -239,6 +242,7 @@ service_load_blob(struct blob_attr *b)
  if (!s)
  return;

+ s->tout_lookup = _tb[SERVICE_TOUT_LOOKUP] ?
blobmsg_get_u32(_tb[SERVICE_TOUT_LOOKUP]) : TOUT_LOOKUP;
  s->port = blobmsg_get_u32(_tb[SERVICE_PORT]);
  s->id = strncpy(d_id, blobmsg_name(b), n);
  if (_tb[SERVICE_INSTANCE])

Comments

Hauke Mehrtens Sept. 4, 2022, 2:30 p.m. UTC | #1
On 8/26/22 13:40, Tobias Waldvogel wrote:
> From: Tobias Waldvogel <tobias.waldvogel@gmail.com>
> 
> Printing on Android devices via mdns IPP does not work
> with the default value of 60 seconds for the
> lookup timeout. It seems that Androd expects an
> immediate answer just when trying to print. Nevertheless
> the umdns debug messages show that the answer is supressed
> due to the timeout. As a result the printer does not
> show up.
> This patch implements an additional parameter
> timeout_lookup for setting a dedicated timeout value
> with a fallback to TOUT_LOOKUP (60s).
> 
> This is a sample ipp service definition, which works
> now with Android standard printing:
> 
> {
>    "ipp": {
>      "service": "_ipp._tcp.local",
>      "instance": "HL3040CN @ router",
>      "port": 631,
>      "timeout_lookup": -1,
>      "txt": [
>        "txtvers=1",
>        "UUID=308f65f9-5393-3027-4c83-374cb704e729",
>        "rp=printers/HL3040CN",
>        "ty=Brother HL3040CN",
>        "note=Office",
>        "pdl=application/pdf,image/jpeg,image/png,image/pwg-raster",
>        "Color=T",
>        "Copies=T"
>      ]
>    }
> }
> 
> Signed-off-by: Tobias Waldvogel <tobias.waldvogel@gmail.com>

The white spaces in this patch are damaged.

It is also broken in patchwork:
https://patchwork.ozlabs.org/project/openwrt/patch/CAAAtp75Fm8OaVryfDZty2bvCCMOh8pns0PXv+LpXpxcXU7hc3A@mail.gmail.com/

You could use "git send-email" to send the patch for example.

Hauke
diff mbox series

Patch

diff --git a/service.c b/service.c
index bd9f985..dc7f330 100644
--- a/service.c
+++ b/service.c
@@ -35,6 +35,7 @@ 
 #include "announce.h"

 enum {
+ SERVICE_TOUT_LOOKUP,
  SERVICE_INSTANCE,
  SERVICE_SERVICE,
  SERVICE_PORT,
@@ -51,12 +52,14 @@  struct service {
  const char *instance;
  const char *service;
  const uint8_t *txt;
+ int32_t tout_lookup;
  int txt_len;
  int port;
  int active;
 };

 static const struct blobmsg_policy service_policy[__SERVICE_MAX] = {
+ [SERVICE_TOUT_LOOKUP] = { .name = "timeout_lookup", .type =
BLOBMSG_TYPE_INT32 },
  [SERVICE_INSTANCE] = { .name = "instance", .type = BLOBMSG_TYPE_STRING },
  [SERVICE_SERVICE] = { .name = "service", .type = BLOBMSG_TYPE_STRING },