Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-integ / recipes-support / dnsmasq / dnsmasq / stx / dnsmasq-update-ipv6-leases-from-config.patch
1 From 1a91b72146893dab1cca1354dd3b0a8fa74d6b55 Mon Sep 17 00:00:00 2001
2 From: Scott Little <scott.little@windriver.com>
3 Date: Tue, 18 Oct 2016 13:07:56 -0400
4 Subject: WRS: Patch22: dnsmasq-update-ipv6-leases-from-config.patch
5
6 ---
7  src/lease.c | 53 +++++++++++++++++++++++++++++++++++++++++++----------
8  1 file changed, 43 insertions(+), 10 deletions(-)
9
10 diff --git a/src/lease.c b/src/lease.c
11 index 69e698c..bc56c47 100644
12 --- a/src/lease.c
13 +++ b/src/lease.c
14 @@ -210,6 +210,18 @@ void lease_init(time_t now)
15    dns_dirty = 1;
16  }
17  
18 +static int lease_match_config_addr(struct dhcp_lease *lease, struct dhcp_config *config)
19 +{
20 +    if (!(lease->flags & (LEASE_TA | LEASE_NA)) && (config->flags & CONFIG_ADDR))
21 +      return (lease->addr.s_addr == config->addr.s_addr);
22 +#ifdef HAVE_DHCP6
23 +    else if ((lease->flags & (LEASE_TA | LEASE_NA)) && (config->flags & CONFIG_ADDR6))
24 +      return IN6_ARE_ADDR_EQUAL(&config->addr6, &lease->addr6);
25 +#endif
26 +    else
27 +      return 0;
28 +}
29 +
30  void lease_update_from_configs(void)
31  {
32    /* changes to the config may change current leases. */
33 @@ -218,16 +230,37 @@ void lease_update_from_configs(void)
34    struct dhcp_config *config;
35    char *name;
36    
37 -  for (lease = leases; lease; lease = lease->next)
38 -    if (lease->flags & (LEASE_TA | LEASE_NA))
39 -      continue;
40 -    else if ((config = find_config(daemon->dhcp_conf, NULL, lease->clid, lease->clid_len, 
41 -                                  lease->hwaddr, lease->hwaddr_len, lease->hwaddr_type, NULL)) && 
42 -            (config->flags & CONFIG_NAME) &&
43 -            (!(config->flags & CONFIG_ADDR) || config->addr.s_addr == lease->addr.s_addr))
44 -      lease_set_hostname(lease, config->hostname, 1, get_domain(lease->addr), NULL);
45 -    else if ((name = host_from_dns(lease->addr)))
46 -      lease_set_hostname(lease, name, 1, get_domain(lease->addr), NULL); /* updates auth flag only */
47 +  for (lease = leases; lease; lease = lease->next) {
48 +    if (lease->flags & LEASE_TA)
49 +      continue;  /* we do not update temporary ipv6 leases */
50 +
51 +    config = find_config(daemon->dhcp_conf, NULL, lease->clid, lease->clid_len,
52 +                         (lease->hwaddr_len > 0 ? lease->hwaddr : NULL),
53 +                         lease->hwaddr_len, lease->hwaddr_type, NULL);
54 +    if (config)
55 +      {
56 +        if ((!(config->flags & (CONFIG_ADDR | CONFIG_ADDR6))) ||
57 +            lease_match_config_addr(lease, config))
58 +          {
59 +            /*
60 +             * Either we matched on a config that doesn't have an address in
61 +             * which case we'll just use the hostname, or we matched on a
62 +             * config that has the same IP address.
63 +             */
64 +            if (!(lease->flags & (LEASE_TA | LEASE_NA)))
65 +              lease_set_hostname(lease, config->hostname, 1, get_domain(lease->addr), NULL);
66 +#ifdef HAVE_DHCP6
67 +            else
68 +              lease_set_hostname(lease, config->hostname, 1, get_domain6(&lease->addr6), NULL);
69 +#endif
70 +            continue;  /* lease updated; move on to next lease */
71 +          }
72 +      }
73 +
74 +    /* attempt to find a matching DNS cache entry for an IPv4 entry */
75 +    if (!(lease->flags & (LEASE_TA | LEASE_NA)) && (name = host_from_dns(lease->addr)))
76 +       lease_set_hostname(lease, name, 1, get_domain(lease->addr), NULL); /* updates auth flag only */
77 +  }
78  }
79   
80  static void ourprintf(int *errp, char *format, ...)
81 -- 
82 2.7.4
83