On 08/02/2017 16:47, Rafał Miłecki wrote:
> From: Rafał Miłecki <ra...@milecki.pl>
> 
> 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 <ra...@milecki.pl>
Acked-by: John Crispin <j...@phrozen.org>

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 <sys/stat.h>
>  
>  #include <fcntl.h>
> +#include <ifaddrs.h>
>  #include <time.h>
>  #include <stdio.h>
>  #include <unistd.h>
> @@ -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(&ifap);
> +
> +     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 *) &sa->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(&sa6->sin6_addr, &ll_prefix, 2))
> +                             dns_add_answer(TYPE_AAAA, (uint8_t *) 
> &sa6->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(&interfaces, 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(&interfaces, 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 <arpa/nameser.h>
>  #include <sys/socket.h>
>  
> -#include <ifaddrs.h>
>  #include <resolv.h>
>  #include <glob.h>
>  #include <stdio.h>
> @@ -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(&ifap);
> -
> -     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 *) &sa->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(&sa6->sin6_addr, &ll_prefix, 2))
> -                             dns_add_answer(TYPE_AAAA, (uint8_t *) 
> &sa6->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 a/service.h b/service.h
> index 49c2aed..c2f51f4 100644
> --- a/service.h
> +++ b/service.h
> @@ -19,6 +19,5 @@ extern void service_cleanup(void);
>  extern void service_announce(struct interface *iface, int ttl);
>  extern void service_announce_services(struct interface *iface, const char 
> *service, int ttl);
>  extern void service_reply(struct interface *iface, const char *match, int 
> ttl);
> -extern void service_reply_a(struct interface *iface, int ttl);
>  
>  #endif
> 

_______________________________________________
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev

Reply via email to