1 /*-------------------------------------------------------------------------
2  * Copyright (C) 2001 Novell, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  *    Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *    Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  *    Neither the name of Novell nor the names of its contributors
17  *    may be used to endorse or promote products derived from this
18  *    software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CALDERA
24  * SYSTEMS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *-------------------------------------------------------------------------*/
32 
33 /** Header file for common DHCP lookup functions.
34  *
35  * @file       slp_dhcp.h
36  * @author     John Calcote (jcalcote@novell.com)
37  * @attention  Please submit patches to http://www.openslp.org
38  * @ingroup    CommonCodeDHCP
39  */
40 
41 #ifndef SLP_DHCP_H_INCLUDED
42 #define SLP_DHCP_H_INCLUDED
43 
44 /*!@defgroup CommonCodeDHCP DHCP
45  * @ingroup CommonCodeNetwork
46  * @{
47  */
48 
49 #include <stddef.h>
50 
51 /* BOOTP/DHCP packet header format:
52  *
53  * Offs  Len   Name     Description
54  * 0     1     opcode   Message opcode: 1 = BOOTREQUEST, 2 = BOOTREPLY
55  * 1     1     htype    Hardware address type (eg., 1 = 10mb ethernet)
56  * 2     1     hlen     Hardware address length (eg., 6 = 10mb ethernet)
57  * 3     1     hops     Client sets to zero, optionally used by relay agents
58  * 4     4     xid      Transaction ID, random number chosen by client
59  * 8     2     secs     Client sets to seconds since start of boot process
60  * 10    2     flags    Bit 0: broadcast response bit
61  * 12    4     ciaddr   Client IP address - only filled if client is bound
62  * 16    4     yiaddr   'your' (Client) IP address
63  * 20    4     siaddr   IP address of next server to use in bootstrap
64  * 24    4     giaddr   Relay agent IP address, used in booting via RA
65  * 28    16    chaddr   Client hardware address
66  * 44    64    sname    Optional server host name, null-terminated string
67  * 108   128   file     Boot file name, null-terminated string
68  * 236   var   options  Optional parameters field
69  *
70  * The options field has the following format:
71  *
72  * Offs  Len   Name     Description
73  * 0     4     cookie   4-byte cookie field: 99.130.83.99 (0x63825363)
74  *
75  * Followed by 1-byte option codes and 1-byte option lengths, except
76  * for the two special fixed length options, pad (0) and end (255).
77  * Options are defined in slp_dhcp.h as TAG_XXX values. The two we
78  * really care about here are options TAG_SLP_DA and TAG_SLP_SCOPE,
79  * 78 and 79, respectively.
80  *
81  * The format for TAG_SLP_DA (starting with the tag) is:
82  *
83  * Offs  Len   Name     Description
84  * 0     1     tag      TAG_SLP_DA - directory agent ip addresses
85  * 1     1     length   length of remaining data in the option
86  * 2     1     mand     flag: the use of these DA's is mandatory
87  * 3     4     a(0)     4-byte ip address
88  * ...
89  * 3+n*4 4     a(n)     4-byte ip address
90  *
91  * The format for TAG_SLP_SCOPE (starting with the tag) is:
92  *
93  * Offs  Len   Name     Description
94  * 0     1     tag      TAG_SLP_SCOPE - directory scopes to use
95  * 1     1     length   length of remaining data in the option
96  * 2     1     mand     flag: the use of these scopes is mandatory
97  * 3     var   scopes   a null-terminated, comma-separated string of scopes
98  *
99  * The "DHCP Message Type" option must be included in every DHCP message.
100  * All tags except for TAG_PAD(0) and TAG_END(255) begin with a tag value
101  * followed by a length of remaining data value.
102  */
103 
104 /** Applicable IANA BOOTP/DHCP option tag values */
105 #define TAG_PAD               0     /*!< Fixed size, 1 byte (0), no length */
106 #define TAG_DHCP_MSG_TYPE     53
107 #define TAG_DHCP_PARAM_REQ    55
108 #define TAG_CLIENT_IDENTIFIER 61
109 #define TAG_SLP_DA            78
110 #define TAG_SLP_SCOPE         79
111 #define TAG_END               255
112 
113 /** Novell format for DHCP TAG_SLP_DA.
114  *
115  * The Novell (pre-rfc2610 or draft 3) format for the DHCP TAG_SLP_DA option
116  * has the 'mandatory' flag containing other bits besides simply 'mandatory'.
117  * These flags are important because if the DA_NAME_PRESENT flag is set, then
118  * we know we are parsing this format, otherwise it's the rfc2610 format.
119  */
120 #define DA_NAME_PRESENT    0x80  /*!< DA name present in option */
121 #define DA_NAME_IS_DNS     0x40  /*!< DA name is host name or DNS name */
122 #define DISABLE_DA_MCAST   0x20  /*!< Multicast for DA's is disabled */
123 #define SCOPE_PRESENT      0x10  /*!< Scope is present in option */
124 
125 /** Character type encodings that we expect to be supported. */
126 #define CT_ASCII     3       /*!< standard 7 or 8 bit ASCII */
127 #define CT_UTF8      106     /*!< UTF-8 */
128 #define CT_UNICODE   1000    /*!< normal Unicode */
129 
130 /** DHCP interface callback type */
131 typedef int DHCPInfoCallBack(int tag, void * optdata,
132       size_t optdatasz, void * context);
133 
134 int DHCPGetOptionInfo(unsigned char * dhcpOptCodes, int dhcpOptCodeCnt,
135       DHCPInfoCallBack * dhcpInfoCB, void * context);
136 
137 int DHCPParseSLPTags(int tag, void * optdata, size_t optdatasz,
138       void * context);
139 
140 /** DHCP interface context structure */
141 typedef struct _DHCPContext
142 {
143    size_t addrlistlen;
144    size_t scopelistlen;
145    char scopelist[256];
146    unsigned char addrlist[256];
147 } DHCPContext;
148 
149 /*! @} */
150 
151 #endif   /* SLP_DHCP_H_INCLUDED */
152 
153 /*=========================================================================*/
154