1/*
2 * Copyright (c) 2000-2012 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24/*
25 * DHCPLease.h
26 * - in-memory and persistent DHCP lease support
27 */
28
29#ifndef _S_DHCPLEASE_H
30#define _S_DHCPLEASE_H
31
32/*
33 * Modification History
34 *
35 * June 11, 2009		Dieter Siegmund (dieter@apple.com)
36 * - split out from ipconfigd.c
37 */
38
39#include <stdbool.h>
40#include <stdint.h>
41#include <netinet/in.h>
42#include <netinet/ip.h>
43#include <netinet/udp.h>
44#include "dhcplib.h"
45#include "timer.h"
46#include "interfaces.h"
47#include "arp_session.h"
48
49/**
50 ** DHCPLease, DHCPLeaseList
51 **/
52typedef struct {
53    bool			tentative;
54    bool			nak;
55    struct in_addr		our_ip;
56    absolute_time_t		lease_start;
57    dhcp_lease_time_t		lease_length;
58    struct in_addr		router_ip;
59    uint8_t			router_hwaddr[MAX_LINK_ADDR_LEN];
60    int				router_hwaddr_length;
61    CFStringRef			ssid;
62    int				pkt_length;
63    uint8_t			pkt[1];
64} DHCPLease, * DHCPLeaseRef;
65
66typedef dynarray_t DHCPLeaseList, * DHCPLeaseListRef;
67
68void
69DHCPLeaseSetNAK(DHCPLeaseRef lease_p, int nak);
70
71
72void
73DHCPLeaseListInit(DHCPLeaseListRef list_p);
74
75void
76DHCPLeaseListFree(DHCPLeaseListRef list_p);
77
78void
79DHCPLeaseListClear(DHCPLeaseListRef list_p,
80		   const char * ifname,
81		   uint8_t cid_type, const void * cid, int cid_length);
82void
83DHCPLeaseListRemoveLease(DHCPLeaseListRef list_p,
84			 struct in_addr our_ip,
85			 struct in_addr router_ip,
86			 const uint8_t * router_hwaddr,
87			 int router_hwaddr_length);
88void
89DHCPLeaseListUpdateLease(DHCPLeaseListRef list_p,
90			 struct in_addr our_ip,
91			 struct in_addr router_ip,
92			 const uint8_t * router_hwaddr,
93			 int router_hwaddr_length,
94			 absolute_time_t lease_start,
95			 dhcp_lease_time_t lease_length,
96			 const uint8_t * pkt, int pkt_length,
97			 CFStringRef ssid);
98arp_address_info_t *
99DHCPLeaseListCopyARPAddressInfo(DHCPLeaseListRef list_p,
100				CFStringRef ssid,
101				absolute_time_t * start_threshold_p,
102				bool tentative_ok,
103				int * ret_count);
104
105
106void
107DHCPLeaseListWrite(DHCPLeaseListRef list_p,
108		   const char * ifname,
109		   uint8_t cid_type, const void * cid, int cid_length);
110void
111DHCPLeaseListRead(DHCPLeaseListRef list_p,
112		  const char * ifname, bool is_wifi,
113		  uint8_t cid_type, const void * cid, int cid_length);
114
115int
116DHCPLeaseListFindLease(DHCPLeaseListRef list_p, struct in_addr our_ip,
117		       struct in_addr router_ip,
118		       const uint8_t * router_hwaddr, int router_hwaddr_length);
119
120static __inline__ int
121DHCPLeaseListCount(DHCPLeaseListRef list_p)
122{
123    return (dynarray_count(list_p));
124}
125
126static __inline__ DHCPLeaseRef
127DHCPLeaseListElement(DHCPLeaseListRef list_p, int i)
128{
129    return (dynarray_element(list_p, i));
130}
131
132void
133DHCPLeaseListRemoveAllButLastLease(DHCPLeaseListRef list_p);
134
135#endif /* _S_DHCPLEASE_H */
136