1 /*
2  * Copyright (c) 2004 Niels Provos <provos@citi.umich.edu>
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31  */
32 
33 /*
34  * Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
35  * All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  *
46  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56  */
57 
58 #ifndef _DHCPCLIENT_H
59 #define _DHCPCLIENT_H
60 
61 #define NC_HOSTADDR   0x01
62 #define NC_GWADDR     0x02
63 #define NC_MASK       0x04
64 #define NC_DOMAIN     0x08
65 #define NC_NSADDR     0x10
66 
67 struct netconf {
68 	struct addr hostaddr;
69 	struct addr gwaddr;
70 	char        domain[256];
71 	struct addr nsaddr[4];
72 	short       defined;
73 };
74 
75 #define DHREQ_STATE_BUSY         0x01
76 #define DHREQ_STATE_WAITANS      0x02
77 #define DHREQ_STATE_WAITACK      0x04
78 
79 struct dhcpclient_req {
80 	int             state;
81 	eth_addr_t      ea;		/* our own */
82 	eth_addr_t	server_ea;	/* from the server */
83 	uint32_t        xid;
84 	struct event    timeoutev;
85 	struct timeval  timer;
86 	struct netconf  nc;
87 	struct addr     servident;
88 	int             ntries;
89 };
90 
91 #define DH_BOOTREQUEST 1
92 #define DH_BOOTREPLY   2
93 
94 #define DH_MAGICCOOKIE 0x63825363
95 
96 #define DH_MSGTYPE_DISCOVER 1
97 #define DH_MSGTYPE_OFFER    2
98 #define DH_MSGTYPE_REQUEST  3
99 #define DH_MSGTYPE_DECLINE  4
100 #define DH_MSGTYPE_ACK      5
101 #define DH_MSGTYPE_NAK      6
102 #define DH_MSGTYPE_RELEASE  7
103 
104 #define DH_SUBNETMASK  1
105 #define DH_ROUTER      3
106 #define DH_NS          6
107 #define DH_HOSTNAME    12
108 #define DH_DOMAINNAME  15
109 #define DH_REQIP       50
110 #define DH_MSGTYPE     53
111 #define DH_SERVIDENT   54
112 #define DH_PARAMREQ    55
113 
114 #define DH_HTYPE_ETHERNET 1
115 
116 struct dhcp_msg {
117 	uint8_t	 dh_op;
118 	uint8_t  dh_htype;
119 	uint8_t  dh_hlen;
120 	uint8_t  dh_hops;
121 	uint32_t dh_xid;
122 	uint16_t dh_secs;
123 	uint16_t dh_flags;
124 	uint32_t dh_ciaddr;
125 	uint32_t dh_yiaddr;
126 	uint32_t dh_siaddr;
127 	uint32_t dh_giaddr;
128 	uint8_t  dh_chaddr[16];
129 	char     dh_sname[64];
130 	char     dh_file[128];
131 	uint32_t dh_magiccookie;
132 	/* And options are packed onto here.. */
133 } __attribute__((__packed__));
134 
135 struct template;
136 int  dhcp_getconf(struct template *);
137 void dhcp_abort(struct template *);
138 int dhcp_release(struct template *);
139 
140 void dhcp_recv_cb(struct eth_hdr *, struct ip_hdr *, u_short);
141 
142 #endif /* _DHCPCLIENT_H */
143