1From 40ef0241afbb49f84e76afd65eb3ee17466bb582 Mon Sep 17 00:00:00 2001
2From: Nate Karstens <nate.karstens@garmin.com>
3Date: Wed, 28 Jun 2017 17:30:00 -0500
4Subject: [PATCH 2/8] Create subroutine for tearing down an interface
5
6Creates a subroutine for tearing down an interface.
7
8Upstream-Status: Submitted [dts@apple.com]
9
10Signed-off-by: Nate Karstens <nate.karstens@garmin.com>
11Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
12---
13 mDNSPosix/mDNSPosix.c | 22 ++++++++++++++++------
14 1 file changed, 16 insertions(+), 6 deletions(-)
15
16Index: mDNSResponder/mDNSPosix/mDNSPosix.c
17===================================================================
18--- mDNSResponder.orig/mDNSPosix/mDNSPosix.c
19+++ mDNSResponder/mDNSPosix/mDNSPosix.c
20@@ -1043,6 +1043,19 @@ mDNSlocal void FreePosixNetworkInterface
21     gRecentInterfaces = intf;
22 }
23
24+mDNSlocal void TearDownInterface(mDNS *const m, PosixNetworkInterface *intf)
25+{
26+    mDNS_DeregisterInterface(m, &intf->coreIntf, NormalActivation);
27+    if (gMDNSPlatformPosixVerboseLevel > 0) fprintf(stderr, "Deregistered interface %s\n", intf->intfName);
28+    FreePosixNetworkInterface(intf);
29+
30+    num_registered_interfaces--;
31+    if (num_registered_interfaces == 0) {
32+        num_pkts_accepted = 0;
33+        num_pkts_rejected = 0;
34+    }
35+}
36+
37 // Grab the first interface, deregister it, free it, and repeat until done.
38 mDNSlocal void ClearInterfaceList(mDNS *const m)
39 {
40@@ -1051,13 +1064,10 @@ mDNSlocal void ClearInterfaceList(mDNS *
41     while (m->HostInterfaces)
42     {
43         PosixNetworkInterface *intf = (PosixNetworkInterface*)(m->HostInterfaces);
44-        mDNS_DeregisterInterface(m, &intf->coreIntf, NormalActivation);
45-        if (gMDNSPlatformPosixVerboseLevel > 0) fprintf(stderr, "Deregistered interface %s\n", intf->intfName);
46-        FreePosixNetworkInterface(intf);
47+        TearDownInterface(m, intf);
48     }
49-    num_registered_interfaces = 0;
50-    num_pkts_accepted = 0;
51-    num_pkts_rejected = 0;
52+
53+    assert(num_registered_interfaces == 0);
54 }
55
56 mDNSlocal int SetupIPv6Socket(int fd)
57