Re: [LEDE-DEV] [PATCH mdns] Rename service_reply_a to dns_reply_a and move it to proper file

2017-02-08 Thread John Crispin


On 08/02/2017 16:47, Rafał Miłecki wrote:
> From: Rafał Miłecki 
> 
> This function doesn't really do anything service specify, it just sends
> an A(AAA) records. It could probably be used even without any services
> registered.
> 
> Signed-off-by: Rafał Miłecki 
Acked-by: John Crispin 

feel free to push the changes to the repo

> ---
>  dns.c   | 32 +++-
>  dns.h   |  1 +
>  interface.c |  2 +-
>  service.c   | 32 +---
>  service.h   |  1 -
>  5 files changed, 34 insertions(+), 34 deletions(-)
> 
> diff --git a/dns.c b/dns.c
> index 63788f7..7ca705e 100644
> --- a/dns.c
> +++ b/dns.c
> @@ -15,6 +15,7 @@
>  #include 
>  
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -180,6 +181,35 @@ dns_send_answer(struct interface *iface, const char 
> *answer)
>   fprintf(stderr, "failed to send question\n");
>  }
>  
> +void
> +dns_reply_a(struct interface *iface, int ttl)
> +{
> + struct ifaddrs *ifap, *ifa;
> + struct sockaddr_in *sa;
> + struct sockaddr_in6 *sa6;
> +
> + getifaddrs();
> +
> + dns_init_answer();
> + for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
> + if (strcmp(ifa->ifa_name, iface->name))
> + continue;
> + if (ifa->ifa_addr->sa_family == AF_INET) {
> + sa = (struct sockaddr_in *) ifa->ifa_addr;
> + dns_add_answer(TYPE_A, (uint8_t *) >sin_addr, 4, 
> ttl);
> + }
> + if (ifa->ifa_addr->sa_family == AF_INET6) {
> + uint8_t ll_prefix[] = {0xfe, 0x80 };
> + sa6 = (struct sockaddr_in6 *) ifa->ifa_addr;
> + if (!memcmp(>sin6_addr, _prefix, 2))
> + dns_add_answer(TYPE_, (uint8_t *) 
> >sin6_addr, 16, ttl);
> + }
> + }
> + dns_send_answer(iface, mdns_hostname_local);
> +
> + freeifaddrs(ifap);
> +}
> +
>  static int
>  scan_name(const uint8_t *buffer, int len)
>  {
> @@ -345,7 +375,7 @@ parse_question(struct interface *iface, char *name, 
> struct dns_question *q)
>   if (host)
>   *host = '\0';
>   if (!strcmp(mdns_hostname, name))
> - service_reply_a(iface, announce_ttl);
> + dns_reply_a(iface, announce_ttl);
>   break;
>   };
>  }
> diff --git a/dns.h b/dns.h
> index 6210e0e..7f3cbe1 100644
> --- a/dns.h
> +++ b/dns.h
> @@ -77,6 +77,7 @@ void dns_send_question(struct interface *iface, const char 
> *question, int type,
>  void dns_init_answer(void);
>  void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength, int 
> ttl);
>  void dns_send_answer(struct interface *iface, const char *answer);
> +void dns_reply_a(struct interface *iface, int ttl);
>  const char* dns_type_string(uint16_t type);
>  void dns_handle_packet(struct interface *iface, struct sockaddr *s, uint16_t 
> port, uint8_t *buf, int len);
>  
> diff --git a/interface.c b/interface.c
> index f09329b..463335a 100644
> --- a/interface.c
> +++ b/interface.c
> @@ -621,7 +621,7 @@ void interface_shutdown(void)
>   vlist_for_each_element(, iface, node)
>   if (iface->fd.fd > 0 && iface->multicast) {
>   service_announce(iface, 0);
> - service_reply_a(iface, 0);
> + dns_reply_a(iface, 0);
>   }
>   vlist_for_each_element(, iface, node)
>   interface_close(iface);
> diff --git a/service.c b/service.c
> index 8d514c2..a3a5bb4 100644
> --- a/service.c
> +++ b/service.c
> @@ -15,7 +15,6 @@
>  #include 
>  #include 
>  
> -#include 
>  #include 
>  #include 
>  #include 
> @@ -118,35 +117,6 @@ service_timeout(struct service *s)
>   return t;
>  }
>  
> -void
> -service_reply_a(struct interface *iface, int ttl)
> -{
> - struct ifaddrs *ifap, *ifa;
> - struct sockaddr_in *sa;
> - struct sockaddr_in6 *sa6;
> -
> - getifaddrs();
> -
> - dns_init_answer();
> - for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
> - if (strcmp(ifa->ifa_name, iface->name))
> - continue;
> - if (ifa->ifa_addr->sa_family == AF_INET) {
> - sa = (struct sockaddr_in *) ifa->ifa_addr;
> - dns_add_answer(TYPE_A, (uint8_t *) >sin_addr, 4, 
> ttl);
> - }
> - if (ifa->ifa_addr->sa_family == AF_INET6) {
> - uint8_t ll_prefix[] = {0xfe, 0x80 };
> - sa6 = (struct sockaddr_in6 *) ifa->ifa_addr;
> - if (!memcmp(>sin6_addr, _prefix, 2))
> - dns_add_answer(TYPE_, (uint8_t *) 
> >sin6_addr, 16, ttl);
> - }
> - }
> - dns_send_answer(iface, mdns_hostname_local);
> -
> - freeifaddrs(ifap);
> -}
> -
>  static void
>  service_reply_single(struct 

[LEDE-DEV] [PATCH mdns] Rename service_reply_a to dns_reply_a and move it to proper file

2017-02-08 Thread Rafał Miłecki
From: Rafał Miłecki 

This function doesn't really do anything service specify, it just sends
an A(AAA) records. It could probably be used even without any services
registered.

Signed-off-by: Rafał Miłecki 
---
 dns.c   | 32 +++-
 dns.h   |  1 +
 interface.c |  2 +-
 service.c   | 32 +---
 service.h   |  1 -
 5 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/dns.c b/dns.c
index 63788f7..7ca705e 100644
--- a/dns.c
+++ b/dns.c
@@ -15,6 +15,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -180,6 +181,35 @@ dns_send_answer(struct interface *iface, const char 
*answer)
fprintf(stderr, "failed to send question\n");
 }
 
+void
+dns_reply_a(struct interface *iface, int ttl)
+{
+   struct ifaddrs *ifap, *ifa;
+   struct sockaddr_in *sa;
+   struct sockaddr_in6 *sa6;
+
+   getifaddrs();
+
+   dns_init_answer();
+   for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+   if (strcmp(ifa->ifa_name, iface->name))
+   continue;
+   if (ifa->ifa_addr->sa_family == AF_INET) {
+   sa = (struct sockaddr_in *) ifa->ifa_addr;
+   dns_add_answer(TYPE_A, (uint8_t *) >sin_addr, 4, 
ttl);
+   }
+   if (ifa->ifa_addr->sa_family == AF_INET6) {
+   uint8_t ll_prefix[] = {0xfe, 0x80 };
+   sa6 = (struct sockaddr_in6 *) ifa->ifa_addr;
+   if (!memcmp(>sin6_addr, _prefix, 2))
+   dns_add_answer(TYPE_, (uint8_t *) 
>sin6_addr, 16, ttl);
+   }
+   }
+   dns_send_answer(iface, mdns_hostname_local);
+
+   freeifaddrs(ifap);
+}
+
 static int
 scan_name(const uint8_t *buffer, int len)
 {
@@ -345,7 +375,7 @@ parse_question(struct interface *iface, char *name, struct 
dns_question *q)
if (host)
*host = '\0';
if (!strcmp(mdns_hostname, name))
-   service_reply_a(iface, announce_ttl);
+   dns_reply_a(iface, announce_ttl);
break;
};
 }
diff --git a/dns.h b/dns.h
index 6210e0e..7f3cbe1 100644
--- a/dns.h
+++ b/dns.h
@@ -77,6 +77,7 @@ void dns_send_question(struct interface *iface, const char 
*question, int type,
 void dns_init_answer(void);
 void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength, int 
ttl);
 void dns_send_answer(struct interface *iface, const char *answer);
+void dns_reply_a(struct interface *iface, int ttl);
 const char* dns_type_string(uint16_t type);
 void dns_handle_packet(struct interface *iface, struct sockaddr *s, uint16_t 
port, uint8_t *buf, int len);
 
diff --git a/interface.c b/interface.c
index f09329b..463335a 100644
--- a/interface.c
+++ b/interface.c
@@ -621,7 +621,7 @@ void interface_shutdown(void)
vlist_for_each_element(, iface, node)
if (iface->fd.fd > 0 && iface->multicast) {
service_announce(iface, 0);
-   service_reply_a(iface, 0);
+   dns_reply_a(iface, 0);
}
vlist_for_each_element(, iface, node)
interface_close(iface);
diff --git a/service.c b/service.c
index 8d514c2..a3a5bb4 100644
--- a/service.c
+++ b/service.c
@@ -15,7 +15,6 @@
 #include 
 #include 
 
-#include 
 #include 
 #include 
 #include 
@@ -118,35 +117,6 @@ service_timeout(struct service *s)
return t;
 }
 
-void
-service_reply_a(struct interface *iface, int ttl)
-{
-   struct ifaddrs *ifap, *ifa;
-   struct sockaddr_in *sa;
-   struct sockaddr_in6 *sa6;
-
-   getifaddrs();
-
-   dns_init_answer();
-   for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
-   if (strcmp(ifa->ifa_name, iface->name))
-   continue;
-   if (ifa->ifa_addr->sa_family == AF_INET) {
-   sa = (struct sockaddr_in *) ifa->ifa_addr;
-   dns_add_answer(TYPE_A, (uint8_t *) >sin_addr, 4, 
ttl);
-   }
-   if (ifa->ifa_addr->sa_family == AF_INET6) {
-   uint8_t ll_prefix[] = {0xfe, 0x80 };
-   sa6 = (struct sockaddr_in6 *) ifa->ifa_addr;
-   if (!memcmp(>sin6_addr, _prefix, 2))
-   dns_add_answer(TYPE_, (uint8_t *) 
>sin6_addr, 16, ttl);
-   }
-   }
-   dns_send_answer(iface, mdns_hostname_local);
-
-   freeifaddrs(ifap);
-}
-
 static void
 service_reply_single(struct interface *iface, struct service *s, const char 
*match, int ttl, int force)
 {
@@ -188,7 +158,7 @@ service_reply(struct interface *iface, const char *match, 
int ttl)
return;
 
if (ttl)
-   service_reply_a(iface, ttl);
+   dns_reply_a(iface, ttl);
 }
 
 void
diff --git