mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-05-12 19:26:52 +08:00
mDNS: move domain related functions and output related funtions
mDNS.c needed to become cleaner. Domain related functions are moved to the mdns_domain.c util module. The output related functions are split off (clear separation between defining the packet and generating the packet). The output functions can now be found in mdns_out.c. mDNS move probe question packet generation to mdns_send_outpacket The probe any questions were added to the pbuf in the send_probe routine. It is better if we move all pbuf generation to the output function so later on packets can be delayed etc. keep it all in one place. mDNS: move legacy question generation to mdns_send_outpacket It's better to do the pbuf generation in one place. Especially important for message delaying etc. mDNS take out domain related functionality and put in other file. The mDNS file is getting very big and a lot still needs to be added. For clarity reasons it's better to split these domain functions from the main mDNS file. mDNS split off output related functionality and put in other file A lot of functions are only needed for the generation of the pbuf, by separating them into another file we clean up the mdns file. We only need the mdns_send_outpacket function as interface. Packet definition is now completely separated from packet generation.
This commit is contained in:
committed by
Dirk Ziegelmeier
parent
1a10a942f2
commit
3043d9d023
@@ -96,6 +96,9 @@ void mdns_resp_announce(struct netif *netif);
|
||||
*/
|
||||
#define mdns_resp_netif_settings_changed(netif) mdns_resp_announce(netif)
|
||||
|
||||
struct mdns_host* netif_mdns_data(struct netif *netif);
|
||||
struct udp_pcb* get_mdns_pcb(void);
|
||||
|
||||
#endif /* LWIP_MDNS_RESPONDER */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
71
src/include/lwip/apps/mdns_domain.h
Normal file
71
src/include/lwip/apps/mdns_domain.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* @file
|
||||
* MDNS responder - domain related functionalities
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015 Verisure Innovation AB
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Erik Ekman <erik@kryo.se>
|
||||
* Author: Jasper Verschueren <jasper.verschueren@apart-audio.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LWIP_HDR_APPS_MDNS_DOMAIN_H
|
||||
#define LWIP_HDR_APPS_MDNS_DOMAIN_H
|
||||
|
||||
#include "lwip/apps/mdns_opts.h"
|
||||
#include "lwip/apps/mdns_priv.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if LWIP_MDNS_RESPONDER
|
||||
|
||||
/* Domain methods - also visible for unit tests */
|
||||
|
||||
err_t mdns_domain_add_label(struct mdns_domain *domain, const char *label, u8_t len);
|
||||
u16_t mdns_readname(struct pbuf *p, u16_t offset, struct mdns_domain *domain);
|
||||
void mdns_domain_debug_print(struct mdns_domain *domain);
|
||||
int mdns_domain_eq(struct mdns_domain *a, struct mdns_domain *b);
|
||||
err_t mdns_build_reverse_v4_domain(struct mdns_domain *domain, const ip4_addr_t *addr);
|
||||
err_t mdns_build_reverse_v6_domain(struct mdns_domain *domain, const ip6_addr_t *addr);
|
||||
err_t mdns_build_host_domain(struct mdns_domain *domain, struct mdns_host *mdns);
|
||||
err_t mdns_build_dnssd_domain(struct mdns_domain *domain);
|
||||
err_t mdns_build_service_domain(struct mdns_domain *domain, struct mdns_service *service, int include_name);
|
||||
u16_t mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain);
|
||||
err_t mdns_write_domain(struct mdns_outpacket *outpkt, struct mdns_domain *domain);
|
||||
|
||||
#endif /* LWIP_MDNS_RESPONDER */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_HDR_APPS_MDNS_DOMAIN_H */
|
||||
85
src/include/lwip/apps/mdns_out.h
Normal file
85
src/include/lwip/apps/mdns_out.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @file
|
||||
* MDNS responder - output related functionalities
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015 Verisure Innovation AB
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Erik Ekman <erik@kryo.se>
|
||||
* Author: Jasper Verschueren <jasper.verschueren@apart-audio.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LWIP_HDR_APPS_MDNS_OUT_H
|
||||
#define LWIP_HDR_APPS_MDNS_OUT_H
|
||||
|
||||
#include "lwip/apps/mdns_opts.h"
|
||||
#include "lwip/apps/mdns_priv.h"
|
||||
#include "lwip/netif.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if LWIP_MDNS_RESPONDER
|
||||
|
||||
/** Bitmasks outmsg generation */
|
||||
/* Probe for ALL types with hostname */
|
||||
#define QUESTION_PROBE_HOST_ANY 0x10
|
||||
/* Probe for ALL types with service instance name */
|
||||
#define QUESTION_PROBE_SERVICE_NAME_ANY 0x10
|
||||
|
||||
/* Lookup from hostname -> IPv4 */
|
||||
#define REPLY_HOST_A 0x01
|
||||
/* Lookup from IPv4/v6 -> hostname */
|
||||
#define REPLY_HOST_PTR_V4 0x02
|
||||
/* Lookup from hostname -> IPv6 */
|
||||
#define REPLY_HOST_AAAA 0x04
|
||||
/* Lookup from hostname -> IPv6 */
|
||||
#define REPLY_HOST_PTR_V6 0x08
|
||||
|
||||
/* Lookup for service types */
|
||||
#define REPLY_SERVICE_TYPE_PTR 0x10
|
||||
/* Lookup for instances of service */
|
||||
#define REPLY_SERVICE_NAME_PTR 0x20
|
||||
/* Lookup for location of service instance */
|
||||
#define REPLY_SERVICE_SRV 0x40
|
||||
/* Lookup for text info on service instance */
|
||||
#define REPLY_SERVICE_TXT 0x80
|
||||
|
||||
err_t mdns_send_outpacket(struct mdns_outmsg *msg);
|
||||
void mdns_prepare_txtdata(struct mdns_service *service);
|
||||
|
||||
#endif /* LWIP_MDNS_RESPONDER */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_HDR_APPS_MDNS_OUT_H */
|
||||
@@ -37,6 +37,7 @@
|
||||
#ifndef LWIP_HDR_MDNS_PRIV_H
|
||||
#define LWIP_HDR_MDNS_PRIV_H
|
||||
|
||||
#include "lwip/apps/mdns.h"
|
||||
#include "lwip/apps/mdns_opts.h"
|
||||
#include "lwip/pbuf.h"
|
||||
|
||||
@@ -46,10 +47,14 @@ extern "C" {
|
||||
|
||||
#if LWIP_MDNS_RESPONDER
|
||||
|
||||
/* Domain struct and methods - visible for unit tests */
|
||||
|
||||
#define MDNS_DOMAIN_MAXLEN 256
|
||||
#define MDNS_READNAME_ERROR 0xFFFF
|
||||
#define NUM_DOMAIN_OFFSETS 10
|
||||
|
||||
#define SRV_PRIORITY 0
|
||||
#define SRV_WEIGHT 0
|
||||
|
||||
/* Domain structs - also visible for unit tests */
|
||||
|
||||
struct mdns_domain {
|
||||
/* Encoded domain name */
|
||||
@@ -60,10 +65,88 @@ struct mdns_domain {
|
||||
u8_t skip_compression;
|
||||
};
|
||||
|
||||
err_t mdns_domain_add_label(struct mdns_domain *domain, const char *label, u8_t len);
|
||||
u16_t mdns_readname(struct pbuf *p, u16_t offset, struct mdns_domain *domain);
|
||||
int mdns_domain_eq(struct mdns_domain *a, struct mdns_domain *b);
|
||||
u16_t mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain);
|
||||
/** Description of a service */
|
||||
struct mdns_service {
|
||||
/** TXT record to answer with */
|
||||
struct mdns_domain txtdata;
|
||||
/** Name of service, like 'myweb' */
|
||||
char name[MDNS_LABEL_MAXLEN + 1];
|
||||
/** Type of service, like '_http' */
|
||||
char service[MDNS_LABEL_MAXLEN + 1];
|
||||
/** Callback function and userdata
|
||||
* to update txtdata buffer */
|
||||
service_get_txt_fn_t txt_fn;
|
||||
void *txt_userdata;
|
||||
/** TTL in seconds of SRV/TXT replies */
|
||||
u32_t dns_ttl;
|
||||
/** Protocol, TCP or UDP */
|
||||
u16_t proto;
|
||||
/** Port of the service */
|
||||
u16_t port;
|
||||
};
|
||||
|
||||
/** Description of a host/netif */
|
||||
struct mdns_host {
|
||||
/** Hostname */
|
||||
char name[MDNS_LABEL_MAXLEN + 1];
|
||||
/** Pointer to services */
|
||||
struct mdns_service *services[MDNS_MAX_SERVICES];
|
||||
/** TTL in seconds of A/AAAA/PTR replies */
|
||||
u32_t dns_ttl;
|
||||
/** Number of probes sent for the current name */
|
||||
u8_t probes_sent;
|
||||
/** State in probing sequence */
|
||||
u8_t probing_state;
|
||||
};
|
||||
|
||||
/** mDNS output packet */
|
||||
struct mdns_outpacket {
|
||||
/** Packet data */
|
||||
struct pbuf *pbuf;
|
||||
/** Current write offset in packet */
|
||||
u16_t write_offset;
|
||||
/** Number of questions written */
|
||||
u16_t questions;
|
||||
/** Number of normal answers written */
|
||||
u16_t answers;
|
||||
/** Number of authoritative answers written */
|
||||
u16_t authoritative;
|
||||
/** Number of additional answers written */
|
||||
u16_t additional;
|
||||
/** Offsets for written domain names in packet.
|
||||
* Used for compression */
|
||||
u16_t domain_offsets[NUM_DOMAIN_OFFSETS];
|
||||
};
|
||||
|
||||
/** mDNS output message */
|
||||
struct mdns_outmsg {
|
||||
/** Netif to send the packet on */
|
||||
struct netif *netif;
|
||||
/** Identifier. Used in legacy queries */
|
||||
u16_t tx_id;
|
||||
/** dns flags */
|
||||
u8_t flags;
|
||||
/** Destination IP/port if sent unicast */
|
||||
ip_addr_t dest_addr;
|
||||
u16_t dest_port;
|
||||
/** If all answers in packet should set cache_flush bit */
|
||||
u8_t cache_flush;
|
||||
/** If reply should be sent unicast */
|
||||
u8_t unicast_reply;
|
||||
/** If legacy query. (tx_id needed, and write
|
||||
* question again in reply before answer) */
|
||||
u8_t legacy_query;
|
||||
/* Question bitmask for host information */
|
||||
u8_t host_questions;
|
||||
/* Questions bitmask per service */
|
||||
u8_t serv_questions[MDNS_MAX_SERVICES];
|
||||
/* Reply bitmask for host information */
|
||||
u8_t host_replies;
|
||||
/* Bitmask for which reverse IPv6 hosts to answer */
|
||||
u8_t host_reverse_v6_replies;
|
||||
/* Reply bitmask per service */
|
||||
u8_t serv_replies[MDNS_MAX_SERVICES];
|
||||
};
|
||||
|
||||
#endif /* LWIP_MDNS_RESPONDER */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user