mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
mDNS: remove netif from mDNS structs
it's more practical to use netif as a wrapper instead of wrapping netif in the mdns packets. netif contains all information. Netif is passed along were needed.
This commit is contained in:
parent
62fb2fd749
commit
4ea5110662
@ -125,8 +125,6 @@ struct mdns_packet {
|
||||
u16_t source_port;
|
||||
/** If packet was received unicast */
|
||||
u16_t recv_unicast;
|
||||
/** Netif that received the packet */
|
||||
struct netif *netif;
|
||||
/** Packet data */
|
||||
struct pbuf *pbuf;
|
||||
/** Current parsing offset in packet */
|
||||
@ -436,7 +434,6 @@ mdns_init_outmsg_with_in_packet(struct mdns_outmsg *out, struct mdns_packet *in)
|
||||
{
|
||||
memset(out, 0, sizeof(struct mdns_outmsg));
|
||||
out->cache_flush = 1;
|
||||
out->netif = in->netif;
|
||||
|
||||
/* Copy source IP/port to use when responding unicast, or to choose
|
||||
* which pcb to use for multicast (IPv4/IPv6)
|
||||
@ -471,7 +468,6 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination)
|
||||
struct mdns_host *mdns = NETIF_TO_HOST(netif);
|
||||
|
||||
memset(&announce, 0, sizeof(announce));
|
||||
announce.netif = netif;
|
||||
announce.cache_flush = 1;
|
||||
#if LWIP_IPV4
|
||||
if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) {
|
||||
@ -498,7 +494,7 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination)
|
||||
announce.dest_port = LWIP_IANA_PORT_MDNS;
|
||||
SMEMCPY(&announce.dest_addr, destination, sizeof(announce.dest_addr));
|
||||
announce.flags = DNS_FLAG1_RESPONSE | DNS_FLAG1_AUTHORATIVE;
|
||||
mdns_send_outpacket(&announce);
|
||||
mdns_send_outpacket(&announce, netif);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -508,13 +504,13 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination)
|
||||
* 3. Put chosen answers in new packet and send as reply
|
||||
*/
|
||||
static void
|
||||
mdns_handle_question(struct mdns_packet *pkt)
|
||||
mdns_handle_question(struct mdns_packet *pkt, struct netif *netif)
|
||||
{
|
||||
struct mdns_service *service;
|
||||
struct mdns_outmsg reply;
|
||||
int i;
|
||||
err_t res;
|
||||
struct mdns_host *mdns = NETIF_TO_HOST(pkt->netif);
|
||||
struct mdns_host *mdns = NETIF_TO_HOST(netif);
|
||||
|
||||
if (mdns->probing_state != MDNS_PROBING_COMPLETE) {
|
||||
/* Don't answer questions until we've verified our domains via probing */
|
||||
@ -542,7 +538,7 @@ mdns_handle_question(struct mdns_packet *pkt)
|
||||
reply.unicast_reply = 1;
|
||||
}
|
||||
|
||||
reply.host_replies |= check_host(pkt->netif, &q.info, &reply.host_reverse_v6_replies);
|
||||
reply.host_replies |= check_host(netif, &q.info, &reply.host_reverse_v6_replies);
|
||||
|
||||
for (i = 0; i < MDNS_MAX_SERVICES; i++) {
|
||||
service = mdns->services[i];
|
||||
@ -577,7 +573,7 @@ mdns_handle_question(struct mdns_packet *pkt)
|
||||
}
|
||||
|
||||
rev_v6 = 0;
|
||||
match = reply.host_replies & check_host(pkt->netif, &ans.info, &rev_v6);
|
||||
match = reply.host_replies & check_host(netif, &ans.info, &rev_v6);
|
||||
if (match && (ans.ttl > (rr_ttl / 2))) {
|
||||
/* The RR in the known answer matches an RR we are planning to send,
|
||||
* and the TTL is less than half gone.
|
||||
@ -609,7 +605,7 @@ mdns_handle_question(struct mdns_packet *pkt)
|
||||
} else if (match & REPLY_HOST_A) {
|
||||
#if LWIP_IPV4
|
||||
if (ans.rd_length == sizeof(ip4_addr_t) &&
|
||||
pbuf_memcmp(pkt->pbuf, ans.rd_offset, netif_ip4_addr(pkt->netif), ans.rd_length) == 0) {
|
||||
pbuf_memcmp(pkt->pbuf, ans.rd_offset, netif_ip4_addr(netif), ans.rd_length) == 0) {
|
||||
LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: A\n"));
|
||||
reply.host_replies &= ~REPLY_HOST_A;
|
||||
}
|
||||
@ -618,7 +614,7 @@ mdns_handle_question(struct mdns_packet *pkt)
|
||||
#if LWIP_IPV6
|
||||
if (ans.rd_length == sizeof(ip6_addr_p_t) &&
|
||||
/* TODO this clears all AAAA responses if first addr is set as known */
|
||||
pbuf_memcmp(pkt->pbuf, ans.rd_offset, netif_ip6_addr(pkt->netif, 0), ans.rd_length) == 0) {
|
||||
pbuf_memcmp(pkt->pbuf, ans.rd_offset, netif_ip6_addr(netif, 0), ans.rd_length) == 0) {
|
||||
LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: AAAA\n"));
|
||||
reply.host_replies &= ~REPLY_HOST_AAAA;
|
||||
}
|
||||
@ -722,7 +718,7 @@ mdns_handle_question(struct mdns_packet *pkt)
|
||||
}
|
||||
}
|
||||
|
||||
mdns_send_outpacket(&reply);
|
||||
mdns_send_outpacket(&reply, netif);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -730,9 +726,9 @@ mdns_handle_question(struct mdns_packet *pkt)
|
||||
* Only prints debug for now. Will need more code to do conflict resolution.
|
||||
*/
|
||||
static void
|
||||
mdns_handle_response(struct mdns_packet *pkt)
|
||||
mdns_handle_response(struct mdns_packet *pkt, struct netif *netif)
|
||||
{
|
||||
struct mdns_host* mdns = NETIF_TO_HOST(pkt->netif);
|
||||
struct mdns_host* mdns = NETIF_TO_HOST(netif);
|
||||
|
||||
/* Ignore all questions */
|
||||
while (pkt->questions_left) {
|
||||
@ -786,9 +782,9 @@ mdns_handle_response(struct mdns_packet *pkt)
|
||||
}
|
||||
|
||||
if (conflict != 0) {
|
||||
sys_untimeout(mdns_probe, pkt->netif);
|
||||
sys_untimeout(mdns_probe, netif);
|
||||
if (mdns_name_result_cb != NULL) {
|
||||
mdns_name_result_cb(pkt->netif, MDNS_PROBING_CONFLICT);
|
||||
mdns_name_result_cb(netif, MDNS_PROBING_CONFLICT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -831,7 +827,6 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
|
||||
memset(&packet, 0, sizeof(packet));
|
||||
SMEMCPY(&packet.source_addr, addr, sizeof(packet.source_addr));
|
||||
packet.source_port = port;
|
||||
packet.netif = recv_netif;
|
||||
packet.pbuf = p;
|
||||
packet.parse_offset = offset;
|
||||
packet.tx_id = lwip_ntohs(hdr.id);
|
||||
@ -855,9 +850,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
|
||||
#endif
|
||||
|
||||
if (hdr.flags1 & DNS_FLAG1_RESPONSE) {
|
||||
mdns_handle_response(&packet);
|
||||
mdns_handle_response(&packet, recv_netif);
|
||||
} else {
|
||||
mdns_handle_question(&packet);
|
||||
mdns_handle_question(&packet, recv_netif);
|
||||
}
|
||||
|
||||
dealloc:
|
||||
@ -905,7 +900,6 @@ mdns_send_probe(struct netif* netif, const ip_addr_t *destination)
|
||||
mdns = NETIF_TO_HOST(netif);
|
||||
|
||||
memset(&outmsg, 0, sizeof(outmsg));
|
||||
outmsg.netif = netif;
|
||||
|
||||
/* Add unicast questions with rtype ANY for all our desired records */
|
||||
outmsg.host_questions = QUESTION_PROBE_HOST_ANY;
|
||||
@ -944,7 +938,7 @@ mdns_send_probe(struct netif* netif, const ip_addr_t *destination)
|
||||
outmsg.tx_id = 0;
|
||||
outmsg.dest_port = LWIP_IANA_PORT_MDNS;
|
||||
SMEMCPY(&outmsg.dest_addr, destination, sizeof(outmsg.dest_addr));
|
||||
res = mdns_send_outpacket(&outmsg);
|
||||
res = mdns_send_outpacket(&outmsg, netif);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -225,11 +225,11 @@ mdns_add_answer(struct mdns_outpacket *reply, struct mdns_domain *domain,
|
||||
/** Write an ANY host question to outpacket */
|
||||
static err_t
|
||||
mdns_add_any_host_question(struct mdns_outpacket *outpkt,
|
||||
struct mdns_outmsg *msg,
|
||||
struct mdns_host *mdns,
|
||||
u16_t request_unicast_reply)
|
||||
{
|
||||
struct mdns_domain host;
|
||||
mdns_build_host_domain(&host, netif_mdns_data(msg->netif));
|
||||
mdns_build_host_domain(&host, mdns);
|
||||
LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Adding host question for ANY type\n"));
|
||||
return mdns_add_question(outpkt, &host, DNS_RRTYPE_ANY, DNS_RRCLASS_IN,
|
||||
request_unicast_reply);
|
||||
@ -251,12 +251,13 @@ mdns_add_any_service_question(struct mdns_outpacket *outpkt,
|
||||
#if LWIP_IPV4
|
||||
/** Write an IPv4 address (A) RR to outpacket */
|
||||
static err_t
|
||||
mdns_add_a_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg)
|
||||
mdns_add_a_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg,
|
||||
struct netif *netif)
|
||||
{
|
||||
err_t res;
|
||||
u32_t ttl = MDNS_TTL_120;
|
||||
struct mdns_domain host;
|
||||
mdns_build_host_domain(&host, netif_mdns_data(msg->netif));
|
||||
mdns_build_host_domain(&host, netif_mdns_data(netif));
|
||||
/* When answering to a legacy querier, we need to repeat the question and
|
||||
* limit the ttl to the short legacy ttl */
|
||||
if(msg->legacy_query) {
|
||||
@ -275,19 +276,20 @@ mdns_add_a_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg)
|
||||
}
|
||||
LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with A record\n"));
|
||||
return mdns_add_answer(reply, &host, DNS_RRTYPE_A, DNS_RRCLASS_IN, msg->cache_flush,
|
||||
ttl, (const u8_t *) netif_ip4_addr(msg->netif),
|
||||
ttl, (const u8_t *) netif_ip4_addr(netif),
|
||||
sizeof(ip4_addr_t), NULL);
|
||||
}
|
||||
|
||||
/** Write a 4.3.2.1.in-addr.arpa -> hostname.local PTR RR to outpacket */
|
||||
static err_t
|
||||
mdns_add_hostv4_ptr_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg)
|
||||
mdns_add_hostv4_ptr_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg,
|
||||
struct netif *netif)
|
||||
{
|
||||
err_t res;
|
||||
u32_t ttl = MDNS_TTL_120;
|
||||
struct mdns_domain host, revhost;
|
||||
mdns_build_host_domain(&host, netif_mdns_data(msg->netif));
|
||||
mdns_build_reverse_v4_domain(&revhost, netif_ip4_addr(msg->netif));
|
||||
mdns_build_host_domain(&host, netif_mdns_data(netif));
|
||||
mdns_build_reverse_v4_domain(&revhost, netif_ip4_addr(netif));
|
||||
/* When answering to a legacy querier, we need to repeat the question and
|
||||
* limit the ttl to the short legacy ttl */
|
||||
if(msg->legacy_query) {
|
||||
@ -313,12 +315,13 @@ mdns_add_hostv4_ptr_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg
|
||||
#if LWIP_IPV6
|
||||
/** Write an IPv6 address (AAAA) RR to outpacket */
|
||||
static err_t
|
||||
mdns_add_aaaa_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg, int addrindex)
|
||||
mdns_add_aaaa_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg,
|
||||
struct netif *netif, int addrindex)
|
||||
{
|
||||
err_t res;
|
||||
u32_t ttl = MDNS_TTL_120;
|
||||
struct mdns_domain host;
|
||||
mdns_build_host_domain(&host, netif_mdns_data(msg->netif));
|
||||
mdns_build_host_domain(&host, netif_mdns_data(netif));
|
||||
/* When answering to a legacy querier, we need to repeat the question and
|
||||
* limit the ttl to the short legacy ttl */
|
||||
if(msg->legacy_query) {
|
||||
@ -337,19 +340,20 @@ mdns_add_aaaa_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg, int
|
||||
}
|
||||
LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with AAAA record\n"));
|
||||
return mdns_add_answer(reply, &host, DNS_RRTYPE_AAAA, DNS_RRCLASS_IN, msg->cache_flush,
|
||||
ttl, (const u8_t *) netif_ip6_addr(msg->netif, addrindex),
|
||||
ttl, (const u8_t *) netif_ip6_addr(netif, addrindex),
|
||||
sizeof(ip6_addr_p_t), NULL);
|
||||
}
|
||||
|
||||
/** Write a x.y.z.ip6.arpa -> hostname.local PTR RR to outpacket */
|
||||
static err_t
|
||||
mdns_add_hostv6_ptr_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg, int addrindex)
|
||||
mdns_add_hostv6_ptr_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg,
|
||||
struct netif *netif, int addrindex)
|
||||
{
|
||||
err_t res;
|
||||
u32_t ttl = MDNS_TTL_120;
|
||||
struct mdns_domain host, revhost;
|
||||
mdns_build_host_domain(&host, netif_mdns_data(msg->netif));
|
||||
mdns_build_reverse_v6_domain(&revhost, netif_ip6_addr(msg->netif, addrindex));
|
||||
mdns_build_host_domain(&host, netif_mdns_data(netif));
|
||||
mdns_build_reverse_v6_domain(&revhost, netif_ip6_addr(netif, addrindex));
|
||||
/* When answering to a legacy querier, we need to repeat the question and
|
||||
* limit the ttl to the short legacy ttl */
|
||||
if(msg->legacy_query) {
|
||||
@ -509,15 +513,16 @@ mdns_add_txt_answer(struct mdns_outpacket *reply, struct mdns_outmsg *msg,
|
||||
|
||||
|
||||
static err_t
|
||||
mdns_add_probe_questions_to_outpacket(struct mdns_outpacket *outpkt, struct mdns_outmsg *msg)
|
||||
mdns_add_probe_questions_to_outpacket(struct mdns_outpacket *outpkt, struct mdns_outmsg *msg,
|
||||
struct netif *netif)
|
||||
{
|
||||
err_t res;
|
||||
int i;
|
||||
struct mdns_host *mdns = netif_mdns_data(msg->netif);
|
||||
struct mdns_host *mdns = netif_mdns_data(netif);
|
||||
|
||||
/* Write host questions (probing or legacy query) */
|
||||
if(msg->host_questions & QUESTION_PROBE_HOST_ANY) {
|
||||
res = mdns_add_any_host_question(outpkt, msg, 1);
|
||||
res = mdns_add_any_host_question(outpkt, mdns, 1);
|
||||
if (res != ERR_OK) {
|
||||
return res;
|
||||
}
|
||||
@ -548,18 +553,18 @@ mdns_add_probe_questions_to_outpacket(struct mdns_outpacket *outpkt, struct mdns
|
||||
* Send the packet
|
||||
*/
|
||||
err_t
|
||||
mdns_send_outpacket(struct mdns_outmsg *msg)
|
||||
mdns_send_outpacket(struct mdns_outmsg *msg, struct netif *netif)
|
||||
{
|
||||
struct mdns_service *service;
|
||||
struct mdns_outpacket outpkt;
|
||||
err_t res = ERR_ARG;
|
||||
int i;
|
||||
struct mdns_host *mdns = netif_mdns_data(msg->netif);
|
||||
struct mdns_host *mdns = netif_mdns_data(netif);
|
||||
u16_t answers = 0;
|
||||
|
||||
memset(&outpkt, 0, sizeof(outpkt));
|
||||
|
||||
res = mdns_add_probe_questions_to_outpacket(&outpkt, msg);
|
||||
res = mdns_add_probe_questions_to_outpacket(&outpkt, msg, netif);
|
||||
if (res != ERR_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -567,14 +572,14 @@ mdns_send_outpacket(struct mdns_outmsg *msg)
|
||||
/* Write answers to host questions */
|
||||
#if LWIP_IPV4
|
||||
if (msg->host_replies & REPLY_HOST_A) {
|
||||
res = mdns_add_a_answer(&outpkt, msg);
|
||||
res = mdns_add_a_answer(&outpkt, msg, netif);
|
||||
if (res != ERR_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
answers++;
|
||||
}
|
||||
if (msg->host_replies & REPLY_HOST_PTR_V4) {
|
||||
res = mdns_add_hostv4_ptr_answer(&outpkt, msg);
|
||||
res = mdns_add_hostv4_ptr_answer(&outpkt, msg, netif);
|
||||
if (res != ERR_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -585,8 +590,8 @@ mdns_send_outpacket(struct mdns_outmsg *msg)
|
||||
if (msg->host_replies & REPLY_HOST_AAAA) {
|
||||
int addrindex;
|
||||
for (addrindex = 0; addrindex < LWIP_IPV6_NUM_ADDRESSES; addrindex++) {
|
||||
if (ip6_addr_isvalid(netif_ip6_addr_state(msg->netif, addrindex))) {
|
||||
res = mdns_add_aaaa_answer(&outpkt, msg, addrindex);
|
||||
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, addrindex))) {
|
||||
res = mdns_add_aaaa_answer(&outpkt, msg, netif, addrindex);
|
||||
if (res != ERR_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -599,7 +604,7 @@ mdns_send_outpacket(struct mdns_outmsg *msg)
|
||||
int addrindex = 0;
|
||||
while (rev_addrs) {
|
||||
if (rev_addrs & 1) {
|
||||
res = mdns_add_hostv6_ptr_answer(&outpkt, msg, addrindex);
|
||||
res = mdns_add_hostv6_ptr_answer(&outpkt, msg, netif, addrindex);
|
||||
if (res != ERR_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -695,8 +700,8 @@ mdns_send_outpacket(struct mdns_outmsg *msg)
|
||||
if (!(msg->host_replies & REPLY_HOST_AAAA)) {
|
||||
int addrindex;
|
||||
for (addrindex = 0; addrindex < LWIP_IPV6_NUM_ADDRESSES; addrindex++) {
|
||||
if (ip6_addr_isvalid(netif_ip6_addr_state(msg->netif, addrindex))) {
|
||||
res = mdns_add_aaaa_answer(&outpkt, msg, addrindex);
|
||||
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, addrindex))) {
|
||||
res = mdns_add_aaaa_answer(&outpkt, msg, netif, addrindex);
|
||||
if (res != ERR_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -707,8 +712,8 @@ mdns_send_outpacket(struct mdns_outmsg *msg)
|
||||
#endif
|
||||
#if LWIP_IPV4
|
||||
if (!(msg->host_replies & REPLY_HOST_A) &&
|
||||
!ip4_addr_isany_val(*netif_ip4_addr(msg->netif))) {
|
||||
res = mdns_add_a_answer(&outpkt, msg);
|
||||
!ip4_addr_isany_val(*netif_ip4_addr(netif))) {
|
||||
res = mdns_add_a_answer(&outpkt, msg, netif);
|
||||
if (res != ERR_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -738,7 +743,7 @@ mdns_send_outpacket(struct mdns_outmsg *msg)
|
||||
LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Sending packet, len=%d, unicast=%d\n",
|
||||
outpkt.write_offset, msg->unicast_reply));
|
||||
|
||||
res = udp_sendto_if(get_mdns_pcb(), outpkt.pbuf, &msg->dest_addr, msg->dest_port, msg->netif);
|
||||
res = udp_sendto_if(get_mdns_pcb(), outpkt.pbuf, &msg->dest_addr, msg->dest_port, netif);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
@ -73,7 +73,7 @@ extern "C" {
|
||||
/* Lookup for text info on service instance */
|
||||
#define REPLY_SERVICE_TXT 0x80
|
||||
|
||||
err_t mdns_send_outpacket(struct mdns_outmsg *msg);
|
||||
err_t mdns_send_outpacket(struct mdns_outmsg *msg, struct netif *netif);
|
||||
void mdns_prepare_txtdata(struct mdns_service *service);
|
||||
|
||||
#endif /* LWIP_MDNS_RESPONDER */
|
||||
|
@ -125,8 +125,6 @@ struct mdns_outpacket {
|
||||
|
||||
/** 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 */
|
||||
|
Loading…
Reference in New Issue
Block a user