00001 /*! \file packets_data.h
00002 This file contains all definitions for DHCP packets data storage.
00003 */
00004
00005
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009
00010 #ifndef PACKETS_DATA_HEADER
00011 #define PACKETS_DATA_HEADER
00012
00013 /*! \brief The constants is used to represent a unknown DSLAM's vendor. */
00014
00015 #define DSLAM_UNKNOWN -1
00016
00017 /*! \brief The constants represents an UT STARCOM DSLAM. */
00018
00019 #define DSLAM_UTSTARCOM 0
00020
00021 /*! \brief The constants represents an ALCATEL DSLAM. */
00022
00023 #define DSLAM_ALCATEL 1
00024
00025 /*! \brief Number of bytes used to store the Node ID (including the final nul character).
00026 \remark <ul>
00027 <li>Alcatel's DSLAMs need up to 20 bytes to represent the node ID.
00028 <li>Utstarcom's DSLAMs need up to 5 bytes (maximum value is "65535" - unsigned shot int).
00029 </ul>
00030 \warning If you modify the value of this constant, you must also modify the value of the constant
00031 NODE_ID_SIZE (see file "tables.h").
00032 */
00033
00034 #define NODE_BUFFER_SIZE 21
00035
00036 /*! \brief This structure contains the option 82 values.
00037 */
00038
00039 struct dhcp82 {
00040 /*! \brief Remote ID sub-option. */
00041
00042 unsigned char sub_option;
00043
00044 /*! \brief Total length of the value fields. */
00045
00046 unsigned char length;
00047
00048 /*! \brief UTStarcom vendor ID. */
00049
00050 unsigned long int vendor_id;
00051
00052 /*! \brief ATM port. */
00053
00054 unsigned char port_type;
00055
00056 /*! \brief Version number. */
00057
00058 unsigned char version;
00059
00060 /*! \brief Port VLAN ID.
00061 \remark For UtStarCom, an 'unsigned short int is enough'. */
00062
00063 unsigned int vlan_id;
00064
00065 /*! \brief MAC address of line card Ethernet port. */
00066
00067 unsigned char nas_mac[6];
00068
00069 /*! \brief GIADDR (0x00 not used by a bridge). */
00070
00071 unsigned long int nas_ip;
00072
00073 /*! \brief DSLAM's node ID.
00074 \remark <ul>
00075 <li>Alcatel's DSLAMs need up to 20 bytes to represent the node ID.
00076 <li>Utstarcom's DSLAMs need up to 5 bytes (maximum value is "65535" - unsigned shot int).
00077 </ul>
00078 */
00079
00080 char node_id[NODE_BUFFER_SIZE];
00081
00082 /*! \brief DSLAM's shelf ID. */
00083
00084 unsigned char shelf;
00085
00086 /*! \brief Slot number. */
00087
00088 unsigned char numero_slot;
00089
00090 /*! \brief Port number. */
00091
00092 unsigned char numero_port;
00093
00094 /*! \brief VPI of port. */
00095
00096 unsigned short int vpi;
00097
00098 /*! \brief VCI of port. */
00099
00100 unsigned short int vci;
00101
00102 /*! \brief DSLAM's constructor (Alcatel or UtStarcom). */
00103
00104 int constructor;
00105 };
00106
00107 /*! \brief For alignement problem, we must use a "per byte" structure.
00108 'unsigned long int' and 'unsigned short int' can not be anywhere in memory.
00109 \warning The structure is used ONLY for "UTSTARCOM" DSLAMs. Do NOT use it fot other DSLAMs.
00110 */
00111
00112 struct m_dhcp82 {
00113 /*! \brief Remote ID sub-option. */
00114
00115 unsigned char sub_option;
00116
00117 /*! \brief Total length of the value fields. */
00118
00119 unsigned char length;
00120
00121 /*! \brief UTStarcom vendor ID. */
00122
00123 unsigned char vendor_id[4];
00124
00125 /*! \brief ATM port. */
00126
00127 unsigned char port_type;
00128
00129 /*! \brief Version number. */
00130
00131 unsigned char version;
00132
00133 /*! \brief Port VLAN ID. */
00134
00135 unsigned char vlan_id[2];
00136
00137 /*! \brief MAC address of line card Ethernet port. */
00138
00139 unsigned char nas_mac[6];
00140
00141 /*! \brief GIADDR (0x00 not used by a bridge). */
00142
00143 unsigned char nas_ip[4];
00144
00145 /*! \brief DSLAM's node ID. */
00146
00147 unsigned char node_id[2];
00148
00149 /*! \brief DSLAM's shelf ID. */
00150
00151 unsigned char shelf;
00152
00153 /*! \brief Slot number. */
00154
00155 unsigned char numero_slot;
00156
00157 /*! \brief Port number. */
00158
00159 unsigned char numero_port;
00160
00161 /*! \brief VPI of port. */
00162
00163 unsigned char vpi;
00164
00165 /*! \brief VCI of port. */
00166
00167 unsigned char vci[2];
00168 };
00169
00170 /*! \brief Maximum number of bytes for a DHCP option value.
00171 */
00172
00173 #define VALUE_MAX_SIZE 2048
00174
00175 /*! \brief This structure is associated with all packets. It is used to store a packet option.
00176 */
00177
00178 struct opt
00179 {
00180 /*! \brief Option's code, as defined in RFCs. */
00181
00182 unsigned char code;
00183
00184 /*! \brief Size of the option's value. */
00185
00186 unsigned char len;
00187
00188 /*! \brief Option's value. */
00189
00190 unsigned char value[VALUE_MAX_SIZE];
00191 };
00192
00193 /*! \brief This structure is associated with all packets. It contains information about the packets.
00194 \warning When a packet is received (via the incoming socket), you must initialize the size of the packet
00195 by calling the function packet_set_taille() (this sets the field 'taille').
00196 */
00197
00198 struct op_control
00199 {
00200 /*! \brief Pointer used to read the option's part of a given DHCP packet. */
00201
00202 char *opt_pointer;
00203
00204 /*! \brief Pointer used to write packet's options. */
00205
00206 unsigned char *opt_pointer_reader;
00207
00208 /*! \brief Total size (in bytes) of the DHCP packet (this include the UDP payload only). */
00209
00210 int taille;
00211
00212 /*! \brief List of options for the DHCP packet. */
00213
00214 struct opt list[256];
00215
00216 /*! \brief Parsed option 82 from DSLAM. */
00217
00218 struct dhcp82 dslam_data;
00219 };
00220
00221 /*! \brief Maximum size for the option's part. This size includes the magic number (4 bytes).
00222 */
00223
00224 #define OPTION_SIZE 2048
00225
00226 /*! \brief Maximum size (in bytes) of a packets.
00227 A packet contains:
00228 <UL>
00229 <LI>A fixed part (which size is 236 bytes). See structure <I>'struct dhcp_packet'</I>.
00230 <LI>A variable lenght part, for the options (maximum of OPTION_SIZE bytes).
00231 </UL>
00232 */
00233
00234 #define PACKET_SIZE (236 + OPTION_SIZE)
00235
00236 /*! \brief Structure of a DHCP packet.
00237 */
00238
00239 struct dhcp_packet
00240 {
00241 /*! \brief opcode. */
00242 unsigned char op;
00243
00244 /*! \brief Hardware type. */
00245 unsigned char htype;
00246
00247 /*! \brief Hardware address length. */
00248 unsigned char hlen;
00249
00250 /*! \brief Hop count (used only by gateway, otherwise 0). */
00251 unsigned char hops;
00252
00253 /*! \brief Transaction ID (random number). */
00254 unsigned long int xid;
00255
00256 /*! \brief Number of seconds since first request. */
00257 unsigned short int secs;
00258
00259 /*! \brief See RFC 1542. */
00260 unsigned short int flags;
00261
00262 /*! \brief Client IP address. */
00263 unsigned long int ciaddr;
00264
00265 /*! \brief Your IP address. */
00266 unsigned long int yiaddr;
00267
00268 /*! \brief Server IP address. */
00269 unsigned long int siaddr;
00270
00271 /*! \brief Gateway IP address. */
00272 unsigned long int giaddr;
00273
00274 /*! \brief Client hardware address. */
00275 char chaddr[16];
00276
00277 /*! \brief Server host name. */
00278 char sname[64];
00279
00280 /*! \brief Boot file name. Form 'op' to 'file' (included), there are 236 bytes. */
00281 char file[128];
00282
00283 /*! \brief options part (4 bytes magic number + raw options). */
00284 char options[OPTION_SIZE];
00285
00286 /*! \brief Operation data. */
00287 struct op_control ctrl;
00288 };
00289
00290 /*! \brief Value for the option 53 (DHCP Message Type): Identifies the DHCP DISCOVER.
00291 */
00292
00293 #define DHCPDISCOVER 1
00294
00295 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP OFFER.
00296 */
00297
00298 #define DHCPOFFER 2
00299
00300 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP REQUEST.
00301 */
00302
00303 #define DHCPREQUEST 3
00304
00305 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP DECLINE.
00306 */
00307
00308 #define DHCPDECLINE 4
00309
00310 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP ACK.
00311 */
00312
00313 #define DHCPACK 5
00314
00315 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP NACK.
00316 */
00317
00318 #define DHCPNAK 6
00319
00320 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP RELEASE.
00321 */
00322
00323 #define DHCPRELEASE 7
00324
00325 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP INFORM.
00326 */
00327
00328 #define DHCPINFORM 8
00329
00330 /*! \brief Value for the option 53 (DHCP Message Type): Identifies the DHCP DISCOVER in string notation.
00331 */
00332
00333 #define DHCPDISCOVER_BYTE "\x01"
00334
00335 /*! \brief Value for the option 53 (DHCP Message Type): Identifies the DHCP DISCOVER in hexa.
00336 */
00337
00338 #define DHCPDISCOVER_HEXA "01"
00339
00340 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP OFFER in string notation.
00341 */
00342
00343 #define DHCPOFFER_BYTE "\x02"
00344
00345 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP OFFER in hexa.
00346 */
00347
00348 #define DHCPOFFER_HEXA "02"
00349
00350 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP REQUEST in string notation.
00351 */
00352
00353 #define DHCPREQUEST_BYTE "\x03"
00354
00355 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP REQUEST in hexa.
00356 */
00357
00358 #define DHCPREQUEST_HEXA "03"
00359
00360 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP DECLINE in string notation.
00361 */
00362
00363 #define DHCPDECLINE_BYTE "\x04"
00364
00365 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP DECLINE in hexa.
00366 */
00367
00368 #define DHCPDECLINE_HEXA "04"
00369
00370 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP ACK in string notation.
00371 */
00372
00373 #define DHCPACK_BYTE "\x05"
00374
00375 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP ACK in hexa.
00376 */
00377
00378 #define DHCPACK_HEXA "05"
00379
00380 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP NACK in string notation.
00381 */
00382
00383 #define DHCPNAK_BYTE "\x06"
00384
00385 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP NACK in hexa.
00386 */
00387
00388 #define DHCPNAK_HEXA "06"
00389
00390 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP RELEASE in string notation.
00391 */
00392
00393 #define DHCPRELEASE_BYTE "\x07"
00394
00395 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP RELEASE in hexa.
00396 */
00397
00398 #define DHCPRELEASE_HEXA "07"
00399
00400 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP INFORM in string notation.
00401 */
00402
00403 #define DHCPINFORM_BYTE "\x08"
00404
00405 /*! \brief Value for the option 53 (DHCP Message Type): dentifies the DHCP INFORM in hexa.
00406 */
00407
00408 #define DHCPINFORM_HEXA "08"
00409
00410 /*! \brief Value for field 'op' of a DHCP packet. If 'op' is set to 'BOOTREQUEST', it means that the packet comes from the client
00411 (to the server).
00412 */
00413
00414 #define BOOTREQUEST 1
00415
00416 /*! \brief Value for field 'op' of a DHCP packet. If 'op' is set to 'BOOTREPLY', it means that the packet comes from the server
00417 (to the client).
00418 */
00419
00420 #define BOOTREPLY 2
00421
00422
00423
00424
00425 #endif
00426
00427 #ifdef __cplusplus
00428 }
00429 #endif
00430
00431
00432
1.2.15